Abstract
Design patterns are standard solutions to recurrent software engineering problems. The use of design patterns helps developers improve software quality. However, when integrating design patterns into their systems, software developers usually do not document their use. To this end, the use of an automatic approach for their detection may accelerate program comprehension, assist developers in software refactoring, and reduce efforts during the maintenance task. In this paper, we propose an attention-based approach for design pattern detection. Specifically, we utilize an automatic feature extraction step with a transformer-based model incorporating the attention mechanism. Based on an unsupervised approach, this step learns from source code to identify code attributes and then produces embedding vectors. These vectors capture syntactic and semantic information related to design pattern implementations and serve as input to train a classifier for the design pattern detection task. The attention mechanism is used to produce important representative features of design pattern implementations and improve the accuracy of the classification model. The evaluation shows that our classifier detects GoF design patterns with an accuracy score of 86%, precision of 87%, recall of 86%, and F1-score of 86%. The comparison of our findings with state-of-the-art methods shows an improvement in (i) precision of 25%, (ii) recall of 6%, and (iii) F1-score of 8%.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Similar content being viewed by others
References
Allamanis, M., Sutton, C.: Mining source code repositories at massive scale using language modeling. In: The 10th Working Conference on Mining Software Repositories, pp. 207–216. IEEE (2013)
Bae, H., Deeb, A., Fleury, A., Zhu, K.: Complexitynet: Increasing llm inference efficiency by learning task complexity. arXiv preprint arXiv:2312.11511 (2023)
Church, K.W.: Word2vec. Nat. Lang. Eng. 23(1), 155–162 (2017)
Dewangan, S., Rao, R.S.: Design pattern detection by using correlation feature selection technique. In: 2022 IEEE 11th International Conference on Communication Systems and Network Technologies (CSNT), pp. 641–645. IEEE (2022)
Dong, J., Zhao, Y., Sun, Y.: A matrix-based approach to recovering design patterns. IEEE Trans. Syst. Man Cybern.-Part A: Syst. Hum. 39(6), 1271–1282 (2009)
Dwivedi, A.K., Tirkey, A., Rath, S.K.: Applying software metrics for the mining of design pattern. In: 2016 IEEE Uttar Pradesh Section International Conference on Electrical, Computer and Electronics Engineering (UPCON), pp. 426–431. IEEE (2016)
Fan, G., Diao, X., Yu, H., Yang, K., Chen, L., et al.: Software defect prediction via attention-based recurrent neural network. Scientific Programming 2019, 6230953 (2019)
Gamma, E., Helm, R., Johnson, R., Vlissides, J.: Design patterns: elements of reusable object-oriented software. Pearson Deutschland GmbH (1995)
Issaoui, I., Bouassida, N., Ben-Abdallah, H.: Using metric-based filtering to improve design pattern detection approaches. Innov. Syst. Softw. Eng. 11, 39–53 (2015)
Komolov, S., Dlamini, G., Megha, S., Mazzara, M.: Towards predicting architectural design patterns: a machine learning approach. Computers 11(10), 151 (2022)
Kouli, M., Rasoolzadegan, A.: A feature-based method for detecting design patterns in source code. Symmetry 14(7), 1491 (2022)
Li, L., Wu, Y., Ye, M.: Experimental comparisons of multi-class classifiers. Informatica 39(1), 71–75 (2015)
Misra, P., Yadav, A.S.: Improving the classification accuracy using recursive feature elimination with cross-validation. Int. J. Emerg. Technol. 11(3), 659–665 (2020)
Munir, H.S., Ren, S., Mustafa, M., Siddique, C.N., Qayyum, S.: Attention based GRU-LSTM for software defect prediction. PLoS ONE 16(3), e0247444 (2021)
Nacef, A., Bahroun, S., Khalfallah, A., Ahmed, S.B.: Features and supervised machine learning based method for singleton design pattern variants detection. Proceedings of the 18th International Conference on Evaluation of Novel Approaches to Software Engineering, ENASE 2023, Prague, Czech Republic, 24–25 April 2023, pp. 226–237 (2023)
Nazar, N., Aleti, A., Zheng, Y.: Feature-based software design pattern detection. J. Syst. Softw. 185, 111179 (2022)
Rasool, G., Philippow, I., Mäder, P.: Design pattern recovery based on annotations. Adv. Eng. Softw. 41(4), 519–526 (2010)
Richards, M., Ford, N.: Fundamentals of software architecture: an engineering approach. O’Reilly Media (2020)
Ruaro, N., et al.: Syml: guiding symbolic execution toward vulnerable states through pattern learning. In: Proceedings of the 24th International Symposium on Research in Attacks, Intrusions and Defenses, pp. 456–468 (2021)
Thaller, H., Linsbauer, L., Egyed, A.: Feature maps: a comprehensible software representation for design pattern detection. In: 2019 IEEE 26th International Conference on Software Analysis, Evolution and Reengineering (SANER), pp. 207–217. IEEE (2019)
Vaswani, A., et al.: Attention is all you need. In: Advances in neural Information Processing Systems, vol. 30 (2017)
Wang, X., Liu, J., Li, L., Chen, X., Liu, X., Wu, H.: Detecting and explaining self-admitted technical debts with attention-based neural networks. In: Proceedings of the 35th IEEE/ACM International Conference on Automated Software Engineering, pp. 871–882 (2020)
Wang, Y., Le, H., Gotmare, A.D., Bui, N.D., Li, J., Hoi, S.C.: Codet5+: Open code large language models for code understanding and generation. arXiv preprint arXiv:2305.07922 (2023)
Zaharia, S., Rebedea, T., Trausan-Matu, S.: Machine learning-based security pattern recognition techniques for code developers. Appl. Sci. 12(23), 12463 (2022)
Zanoni, M., Fontana, F.A., Stella, F.: On applying machine learning techniques for design pattern detection. J. Syst. Softw. 103, 102–117 (2015)
Zhou, P., et al.: Attention-based bidirectional long short-term memory networks for relation classification. In: Proceedings of the 54th Annual Meeting of the Association for Computational Linguistics (volume 2: Short papers), pp. 207–212 (2016)
Zhu, H., Bayley, I., Shan, L., Amphlett, R.: Tool support for design pattern recognition at model level. In: 2009 33rd Annual IEEE International Computer Software and Applications Conference, vol. 1, pp. 228–233. IEEE (2009)
Author information
Authors and Affiliations
Corresponding author
Editor information
Editors and Affiliations
Ethics declarations
Data Availability
The data that supports the findings is available through Zenodo (https://doi.org/10.5281/zenodo.11584286).
Rights and permissions
Copyright information
© 2024 The Author(s), under exclusive license to Springer Nature Switzerland AG
About this paper
Cite this paper
Mzid, R., Rezgui, I., Ziadi, T. (2024). Attention-Based Method for Design Pattern Detection. In: Galster, M., Scandurra, P., Mikkonen, T., Oliveira Antonino, P., Nakagawa, E.Y., Navarro, E. (eds) Software Architecture. ECSA 2024. Lecture Notes in Computer Science, vol 14889. Springer, Cham. https://doi.org/10.1007/978-3-031-70797-1_6
Download citation
DOI: https://doi.org/10.1007/978-3-031-70797-1_6
Published:
Publisher Name: Springer, Cham
Print ISBN: 978-3-031-70796-4
Online ISBN: 978-3-031-70797-1
eBook Packages: Computer ScienceComputer Science (R0)