🤖 AI Summary
Identifying design pattern instances in unfamiliar codebases remains challenging due to reliance on explicit annotations and rigid syntactic templates in traditional static analysis. Method: This paper pioneers the integration of large language models (LLMs) into design pattern detection, shifting focus from syntax-based matching to semantic role identification of classes. We propose a hybrid approach combining fine-tuning and prompt engineering, incorporating formal pattern role definitions, context-aware code slicing, and multi-turn reasoning for validation—adapted to CodeLlama and DeepSeek-Coder. Results: Evaluated on 12 open-source projects, our method achieves an average F1-score of 86.3%, substantially outperforming existing tools. It supports all 7 Gang-of-Four patterns and robustly detects implicit implementations, thereby enhancing software architecture comprehension, refactoring decision-making, and cross-project knowledge transfer.
📝 Abstract
Detecting design pattern instances in unfamiliar codebases remains a challenging yet essential task for improving software quality and maintainability. Traditional static analysis tools often struggle with the complexity, variability, and lack of explicit annotations that characterize real-world pattern implementations. In this paper, we present a novel approach leveraging Large Language Models to automatically identify design pattern instances across diverse codebases. Our method focuses on recognizing the roles classes play within the pattern instances. By providing clearer insights into software structure and intent, this research aims to support developers, improve comprehension, and streamline tasks such as refactoring, maintenance, and adherence to best practices.