Strategies for Guiding LLMs to Use Software Design Patterns: A Case of Singleton Companion Proceedings of the 34th ACM Symposium on the Foundations of Software Engineering (FSE ’26), June 5–9, 2026, Montreal, Canada Conference: 22nd International Conference on Predictive Models and Data Analytics in Software Engineering; July 05, 2026; Montreal, QC, Canada 22nd International Conference on Predictive Models and Data Analytics in Software Engineering (PROMISE ’26), July 05, 2026, Montreal, QC, Canada DOI: 10.1145/3803846.3807469 ISBN: 979-8-4007-2584-5/2026/07 CCS: Software and its engineering Design patterns CCS: Computing methodologies Natural language processing CCS: Software and its engineering Functionality

Viktor Kjellberg, Farnaz Fotrousi, Miroslaw Staron · 2026

Read Strategies for Guiding LLMs to Use Software Design Patterns: A Case of Singleton Companion Proceedings of the 34th ACM Symposium on the Foundations of Software Engineering (FSE ’26), June 5–9, 2026, Montreal, Canada Conference: 22nd International Conference on Predictive Models and Data Analytics in Software Engineering; July 05, 2026; Montreal, QC, Canada 22nd International Conference on Predictive Models and Data Analytics in Software Engineering (PROMISE ’26), July 05, 2026, Montreal, QC, Canada DOI: 10.1145/3803846.3807469 ISBN: 979-8-4007-2584-5/2026/07 CCS: Software and its engineering Design patterns CCS: Computing methodologies Natural language processing CCS: Software and its engineering Functionality by Viktor Kjellberg, Farnaz Fotrousi, Miroslaw Staron (2026) in the Tower of Babel, a free online library of public-domain works preserved in clean, searchable text. No sign-up. The full text is served as a plain-text file at a predictable URL, where text is present: https://antarctic-labs.com/tower-of-babel/arxiv-2605-26898.txt.

Introduction

Kjellberg, Fotrousi, and Staron test four prompting strategies for guiding 13 language models to use the Singleton design pattern in Java code. The best strategy depends on the model, but iterative binary feedback gives the best overall alignment while preserving or improving functionality. With plain instructions, Llama 3.3 produced Singleton classes in every case and raised tests passed by 34.1 percentage points. Even simple guidance strategies, they conclude, can steer models toward design patterns.

Catalog record

CREATORViktor Kjellberg, Farnaz Fotrousi, Miroslaw Staron
YEAR2026
COLLECTIONPAPERS
FORMATTXT
FILE SIZE44930
LICENSEhttp://creativecommons.org/licenses/by/4.0/
RIGHTSCC BY
SOURCEarXiv

Source: https://arxiv.org/abs/2605.26898

Browse the full library · About the Tower of Babel

Full text

The opening of the work, from the library's hosted text:

Strategies for Guiding LLMs to Use Software Design Patterns: A Case of Singleton Companion Proceedings of the 34th ACM Symposium on the Foundations of Software Engineering (FSE ’26), June 5–9, 2026, Montreal, Canada Conference: 22nd International Conference on Predictive Models and Data Analytics in Software Engineering; July 05, 2026; Montreal, QC, Canada 22nd International Conference on Predictive Models and Data Analytics in Software Engineering (PROMISE ’26), July 05, 2026, Montreal, QC, Canada DOI: 10.1145/3803846.3807469 ISBN: 979-8-4007-2584-5/2026/07 CCS: Software and its engineering Design patterns CCS: Computing methodologies Natural language processing CCS: Software and its engineering Functionality Viktor Kjellberg, Farnaz Fotrousi, Miroslaw Staron Abstract . Large Language Models (LLMs) can generate functional source code from natural-language prompts, but often fail to consistently follow higher-level architectural structures or design patterns. Since LLMs are increasingly used in software engineering, their ability to apply established design principles to generated code is crucial to the long-term success of software products. Therefore, the goal of this paper is to identify strategies for guiding LLMs to incorporate design patterns into the generated source code. We designed a computational experiment to evaluate the ability of 13 LLMs to generate code that follows the Singleton design pattern, using four prompting strategies: instructions, binary automated feedback, extensive automated feedback, and extensive feedback with few-shot prompts, in 164 Java coding challenges from HumanEval-X. Our results shows that the optimal strategy to guide LLMs to include design patterns depends heavily on the type of model. Still, overall, iterative binary feedback provides the best alignment with Singleton while preserving or improving the code’s functionality. With guiding with instructions, Llama 3.3 generated Singleton classes in 100% of cases and improved code functionality, increasing the number of tests passed by 34.1 percentage points. It achieved a similar result with guidance through instructions and binary feedback. Qwen 3 (8B) increased the alignment with Singleton to 99.2% and the functionality to 58.6% using binary feedback. Our result suggests that even simple strategies can be used to guide LLMs to use design patterns. † † cc-license: by 1. Introduction Large Language Models (LLMs) have gained acceptance in the software engineering industry thanks to tools like GitHub Copilot and Claude Code. They provide software engineers with a boost in productivity in implementation, testing, requirements engineering, and code review. At the same time, software engineering is more than just programming or testing; it is also about good design, robust software construction, and reliable software operations. Software design patterns are a good example of software engineering knowledge that is used in many industries to standardize the implementation of recurring patterns in software ( 6 ) . It is a way for developers to use a shared language among themselves and to instantly identify the behavior of design concepts ( 3 ) . Architectural patterns and secure software design patterns are additional examples of these ( 13 ) . In the age of LLMs, an ever-increasing share of code is generated by these models, and they have become an essential tool for many developers by assisting with tasks ranging from implementing new features to refactoring ( 18 ) . However, while these models can generate functional, syntactically correct code at the low level, they do not adhere to higher-level design principles such as modularity and abstraction ( 8 ) . In particular, design patterns are seldom applied correctly in LLM-generated code ( 14 ) . The authors of the classical GoF (Gang of Four) patterns ( 6 ) have identified 23 common design patterns, which are studied extensively in software engineering. One of these is the Singleton design pattern, whose intent is defined as to "Ensure a class only has one instance, and provide a global point of access to it" ( 6 ) . This pattern is used in complex systems where it is important that only a single instance of a given class can exist at any given time. This could be logging, database connections, or the software object representing a car engine. The Singleton design pattern is a creational pattern; its properties are defined during code creation, making it easy to recognize and automatically detect. In this paper, we investigate how to guide LLMs towards generating code that follows the Singleton design pattern. This study is important to us because it helps us determine whether we can use existing LLMs alongside design pattern recognition/design software to generate new software code. We conduct a computational experiment where we explore prompting strategies and tool-assisted automated feedback strategies. We also study whether these strategies have an impact (potentially detrimental) on the functionality of the generated source code. Firstly, we study how to guide the LLMs to generate code that follows the Singleton design pattern using direct instructions. RQ1: To what extent do direct instructions prompting strategies influence a model’s ability to generate codes that correctly implement the Singleton design pattern? In this research question, we evaluate whether models can successfully generate code that follows the Singleton design pattern when instructed to do so. Secondly, we provide the models with feedback on how well the generated code aligns with the Singleton pattern and allow them additional attempts to generate correct code. RQ2: To what extent does automated feedback help LLMs align the code to the Singleton design pattern? We experimented with binary feedback, where we solely inform the LLM whether the generated code follows the Singleton design pattern, as well as with more extensive feedback indicating which properties of Singleton are fulfilled and which are not. The extensive feedback was also paired with examples of correctly implemented Singleton classes to help the LLMs. Lastly, we want to understand how these strategies will affect our ability to implement the Singleton pattern without negatively affecting the overall functional correctness of the generated code. This is formulated as the following research question: RQ3: To what extent can LLMs be guided to generate Java classes following the Singleton design pattern, without negatively affecting the functionality of the code? Our experiments show that we can guide LLMs to implement the Singleton design pattern in the generated code without negatively affecting their functionality. However, the optimal strategy depends on which LLM is used. The rest of the paper is structured as follows. Section 2 reviews previous studies related to design patterns and prompting strategies. In Section 3 , the dataset, evaluation metric, and requirements for a Singleton class are presented. Section 4 consists of a detailed description of the experiment design used in the four experiments. The results of the trials are presented in 5 . Figure 1 . A class representing the software of an engine. To the left, without implementing Singleton. On the right, the engine class is implemented as a Singleton. The arrows point toward the rows, which show that it is a Singleton class. 2. Related Work Our study builds on the existing work in design pattern recognition, automated design, and prompting strategies in software development. 2.1. Automated Design 22 uses a method called \mu FiX to refine the program’s specifications in the tasks. The system receives a natural-language explanation of the expected output along with a definition of the function. The LLM then generates a natural-language description of the specifications and iteratively identifies logical errors

Read the complete text