B. Zisa, L. Passaro and J. Soldani, "Design Pattern-Based Code Refactoring with LLMs," 2026 IEEE International Conference on Software Analysis, Evolution and Reengineering (SANER), Limassol, Cyprus, 2026, pp. 222-227, doi: 10.1109/SANER67736.2026.00033.

Abstract: Design pattern enhance software maintainability, but manually introducing them by refactoring existing codebases remains costly. This paper investigates the potential of Large Language Models (LLMs) to automate design pattern-based code refactoring. We propose a structured, test-driven method that guides LLMs to refactor existing codebases by introducing design patterns while preserving behavioral equivalence. We also introduce an open-source Python tool implementing our proposed method. Then, to assess our proposal, we introduce a curated dataset encompassing canonical and custom examples, which we use to run controlled experiments. Our experiments compare two state-of-the-art LLMs (i.e., GPT-4o and Gemini 2.5 Flash Preview), showing that both models reliably preserve functionality, with Gemini anyhow better instantiating the target design patterns. More generally, our findings indicate that LLMs can effectively support structured, pattern-oriented refactoring, contributing to improved maintainability in evolving software systems and a potential reduction in technical debt.