IEEE Access (Jan 2025)

Context Is All You Need: A Hybrid Attention-Based Method for Detecting Code Design Patterns

  • Tarik Houichime,
  • Younes El Amrani

DOI
https://doi.org/10.1109/ACCESS.2025.3525849
Journal volume & issue
Vol. 13
pp. 9689 – 9707

Abstract

Read online

Software reverse engineering plays a crucial role in identifying design patterns and reconstructing software architectures by analyzing system implementations and producing abstract representations across multiple layers. This research introduces a novel feature engineering approach that integrates both behavioral and structural analysis of code, resulting in a feature-rich sequential representation. This transformation enables the effective use of transformers and attention mechanisms to detect design patterns in source code. Our results emphasize the importance of context in distinguishing between various design patterns, demonstrating that the proposed sequence format, with its sensitivity to token order, significantly improves the model’s capacity to differentiate between similar patterns. By leveraging the power of attention mechanisms, our approach efficiently discards irrelevant code elements, focusing on the most critical features for accurate patterns detection. Additionally, we show that this sequential code representation can be utilized to augment training data, leading to enhanced model accuracy. Trained on a diverse set of code samples representing all 23 GoF design patterns, sourced from repositories such as GitHub and Bitbucket, our methodology achieved an accuracy of 92%. Evaluation metrics further validate the robustness of the approach. This study underscores the potential of context-driven, feature-engineered representations in advancing design patterns detection and contributes a comprehensive new dataset that supports behavioral code analysis, setting the stage for future research in this area.

Keywords