Skip to main content

Attention-Based Method for Design Pattern Detection

  • Conference paper
  • First Online:
Software Architecture (ECSA 2024)

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%.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Subscribe and save

Springer+ Basic
¥17,985 /Month
  • Get 10 units per month
  • Download Article/Chapter or eBook
  • 1 Unit = 1 Article or 1 Chapter
  • Cancel anytime
Subscribe now

Buy Now

Chapter
JPY 3498
Price includes VAT (Japan)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
JPY 7550
Price includes VAT (Japan)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
JPY 9437
Price includes VAT (Japan)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Notes

  1. 1.

    https://huggingface.co/Salesforce/codet5p-110m-embedding.

References

  1. 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)

    Google Scholar 

  2. Bae, H., Deeb, A., Fleury, A., Zhu, K.: Complexitynet: Increasing llm inference efficiency by learning task complexity. arXiv preprint arXiv:2312.11511 (2023)

  3. Church, K.W.: Word2vec. Nat. Lang. Eng. 23(1), 155–162 (2017)

    Article  Google Scholar 

  4. 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)

    Google Scholar 

  5. 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)

    Article  Google Scholar 

  6. 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)

    Google Scholar 

  7. 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)

    Google Scholar 

  8. Gamma, E., Helm, R., Johnson, R., Vlissides, J.: Design patterns: elements of reusable object-oriented software. Pearson Deutschland GmbH (1995)

    Google Scholar 

  9. 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)

    Article  Google Scholar 

  10. Komolov, S., Dlamini, G., Megha, S., Mazzara, M.: Towards predicting architectural design patterns: a machine learning approach. Computers 11(10), 151 (2022)

    Article  Google Scholar 

  11. Kouli, M., Rasoolzadegan, A.: A feature-based method for detecting design patterns in source code. Symmetry 14(7), 1491 (2022)

    Article  Google Scholar 

  12. Li, L., Wu, Y., Ye, M.: Experimental comparisons of multi-class classifiers. Informatica 39(1), 71–75 (2015)

    Google Scholar 

  13. 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)

    Google Scholar 

  14. 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)

    Article  Google Scholar 

  15. 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)

    Google Scholar 

  16. Nazar, N., Aleti, A., Zheng, Y.: Feature-based software design pattern detection. J. Syst. Softw. 185, 111179 (2022)

    Article  Google Scholar 

  17. Rasool, G., Philippow, I., Mäder, P.: Design pattern recovery based on annotations. Adv. Eng. Softw. 41(4), 519–526 (2010)

    Article  Google Scholar 

  18. Richards, M., Ford, N.: Fundamentals of software architecture: an engineering approach. O’Reilly Media (2020)

    Google Scholar 

  19. 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)

    Google Scholar 

  20. 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)

    Google Scholar 

  21. Vaswani, A., et al.: Attention is all you need. In: Advances in neural Information Processing Systems, vol. 30 (2017)

    Google Scholar 

  22. 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)

    Google Scholar 

  23. 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)

  24. Zaharia, S., Rebedea, T., Trausan-Matu, S.: Machine learning-based security pattern recognition techniques for code developers. Appl. Sci. 12(23), 12463 (2022)

    Article  Google Scholar 

  25. Zanoni, M., Fontana, F.A., Stella, F.: On applying machine learning techniques for design pattern detection. J. Syst. Softw. 103, 102–117 (2015)

    Article  Google Scholar 

  26. 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)

    Google Scholar 

  27. 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)

    Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Rania Mzid .

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

Reprints and permissions

Copyright information

© 2024 The Author(s), under exclusive license to Springer Nature Switzerland AG

About this paper

Check for updates. Verify currency and authenticity via CrossMark

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)

Publish with us

Policies and ethics