y0news
← Feed
Back to feed
🧠 AI NeutralImportance 6/10

Strategies for Guiding LLMs to Use Software Design Patterns: A Case of Singleton

arXiv – CS AI|Viktor Kjellberg, Farnaz Fotrousi, Miroslaw Staron|
🤖AI Summary

Researchers evaluated 13 large language models' ability to generate code following the Singleton design pattern across four prompting strategies, finding that iterative binary feedback and instruction-based guidance most effectively guide LLMs to incorporate architectural best practices while maintaining code functionality.

Analysis

This research addresses a critical gap in AI-assisted software development: while LLMs excel at generating functional code snippets, they struggle to apply established architectural principles consistently. The study's systematic evaluation of 13 models against 164 Java challenges reveals that design pattern adherence is not inherent to code generation but rather trainable through deliberate prompting strategies. This distinction matters significantly for enterprise software development, where architectural consistency determines long-term maintainability and scalability. The finding that optimal strategies vary by model type—Llama 3.3 achieved 100% Singleton compliance with instruction guidance while Qwen 3 excelled with binary feedback—suggests that practitioners must tailor approaches based on specific models rather than assuming universal solutions. From a software engineering perspective, the success of iterative binary feedback indicates that LLMs respond well to structured, incremental correction mechanisms, mirroring how human developers learn through code review cycles. The preservation or improvement of code functionality alongside pattern adherence demonstrates these strategies avoid the common pitfall of optimizing for one metric at the expense of another. For developers and organizations increasingly relying on LLM-assisted coding, this research provides actionable frameworks for ensuring generated code meets both functional and architectural requirements. The relatively simple nature of successful strategies—basic instructions and binary yes/no feedback—lowers implementation barriers for integrating design pattern guidance into development workflows, potentially accelerating enterprise adoption of AI coding assistants.

Key Takeaways
  • Iterative binary feedback proved most effective overall for guiding LLMs to implement Singleton design patterns while maintaining code functionality.
  • Optimal prompting strategies vary significantly by model type, requiring practitioners to evaluate and customize approaches per specific LLM.
  • Llama 3.3 achieved 100% Singleton pattern compliance with instruction-based guidance and improved functionality by 34.1 percentage points.
  • Simple prompting strategies like instructions and binary feedback can effectively guide LLMs toward architectural best practices without complex mechanisms.
  • Design pattern adherence in LLM-generated code is trainable rather than inherent, opening pathways for systematic improvement in AI-assisted software development.
Mentioned in AI
Models
LlamaMeta
Read Original →via arXiv – CS AI
Act on this with AI
Stay ahead of the market.
Connect your wallet to an AI agent. It reads balances, proposes swaps and bridges across 15 chains — you keep full control of your keys.
Connect Wallet to AI →How it works
Related Articles