Strategies for Guiding LLMs to Use Software Design Patterns: A Case of Singleton
Paper i proceeding, 2026

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.

Design Pattern

LLM

Program Synthesis

Författare

Viktor Kjellberg

Göteborgs universitet

Chalmers, Data- och informationsteknik, Interaktionsdesign och Software Engineering

Farnaz Fotrousi

Göteborgs universitet

Chalmers, Data- och informationsteknik, Interaktionsdesign och Software Engineering

Miroslaw Staron

Chalmers, Data- och informationsteknik, Software Engineering

Göteborgs universitet

PROCEEDINGS OF THE 2026 22ND INTERNATIONAL CONFERENCE ON PREDICTIVE MODELS AND DATA ANALYTICS IN SOFTWARE ENGINEERING, PROMISE 2026

91-100
979-8-4007-2584-5 (ISBN)

22nd International Conference on Predictive Models and Data Analytics in Software Engineering-PROMISE
Montreal, Canada,

Ämneskategorier (SSIF 2025)

Programvaruteknik

DOI

10.1145/3803846.3807469

Mer information

Senast uppdaterat

2026-11-20