An Efficient Design Smell Detection Approach with Inter-class Relation (S)

Hao Zhu, Yichen Li, Jie Li, Xiaofang ZhangSEKE 2023 · OpenReview

Introduction

In modern software engineering, maintaining high code quality is essential to prevent the accumulation of "technical debt." While many automated tools effectively identify implementation-level issues—often referred to as code smells—they frequently struggle with higher-level architectural flaws known as design smells. Design smells, such as Broken Hierarchy or Insufficient Modularization, are particularly damaging because they involve complex interactions across multiple classes rather than isolated snippets of code.

This paper introduces DSIR (Design Smell Detection via Inter-class Relation), a novel deep learning framework designed to bridge this gap. By integrating both local code syntax and global structural relationships, DSIR offers a more holistic approach to identifying structural decay in software systems.

The Challenge of Design Smells

Traditional detection methods typically rely on raw text tokens or Abstract Syntax Trees (ASTs) of individual files. While these are sufficient for finding a "Long Method" or "Magic Number," they fail to capture the "big picture" context required for design smells. For instance, a Broken Hierarchy cannot be detected by looking at a single class; it requires understanding how that class relates to its parents and siblings. The authors argue that incorporating inter-class relationships—specifically those defined in UML class diagrams—is critical for accurate architectural analysis.

Methodology: The DSIR Framework

DSIR utilizes a dual-stream architecture to process software from two distinct perspectives: syntax and structure.

Overview of the DSIR framework, illustrating the parallel processing of AST tokens via BiLSTM and UML class diagrams via R-GCN.

1. Capturing Code Syntax

The first stream focuses on the internal logic of classes. Source code is parsed into an AST using the javalang library. Rather than using raw tokens, DSIR employs a preorder traversal to extract a sequence of AST node tokens. This sequence is processed by a Bidirectional Long Short-Term Memory (BiLSTM) network equipped with an attention mechanism, allowing the model to prioritize the most relevant structural elements within long code sequences.

2. Capturing Structural Relations

The core innovation of DSIR is its second stream, which builds a class-level semantic graph. In this graph, nodes represent classes (containing metadata like attributes and methods), and edges represent four fundamental UML relationships: dependency, inheritance, association, and implementation. This graph is fed into a Relational Graph Convolutional Network (R-GCN), which is uniquely capable of distinguishing between different types of relational edges.

3. Model Fusion

The outputs from the BiLSTM (syntax) and R-GCN (structure) are merged through a weighted fusion layer. This combined representation is then passed to a classifier to determine if a specific design smell is present.

Experimental Results

The researchers evaluated DSIR using a dataset of 500 high-quality Java projects from GitHub, with ground-truth labels provided by the Designite tool. The model was tested against three primary smells: Broken Hierarchy, Insufficient Modularization, and Deficient Encapsulation.

Performance evaluation of DSIR: (a) Learning rate sensitivity, (b) Batch size sensitivity, and (c) F1-score distribution across different design smell categories.

DSIR achieved an Average F1-score of 0.71, representing a 31% improvement over previous state-of-the-art methods like ASTNN. Statistical validation via the Wilcoxon signed-rank test confirmed that these gains are significant, with a "Large" effect size. As shown in the performance box plots, the model maintains robust performance across various hyperparameter configurations, though it is particularly effective at identifying Insufficient Modularization.

Key Insights and Discussion

  • The Power of Context: An ablation study showed that removing the R-GCN stream caused the F1-score for Insufficient Modularization to drop by 47%, proving that structural context is the primary driver for detecting complex design flaws.
  • Syntax vs. Structure: While the R-GCN excels at hierarchy issues, the BiLSTM stream remains vital for Deficient Encapsulation. This suggests that encapsulation issues are often contained within the class's own members, whereas modularization is a global property.
  • AST Expressiveness: Using AST node tokens instead of raw text provides a more compact and expressive representation of code logic, which is essential for the long snippets typical of design-level problems.

Conclusion

DSIR demonstrates that design smell detection can be significantly improved by treating software as a multi-relational graph rather than just a collection of text files. By combining BiLSTM-based syntax analysis with R-GCN-based structural analysis, the approach provides a powerful tool for developers to manage technical debt. Future work will focus on extending this approach to other programming languages like Python and C++, and expanding the library of detectable design smells.

Summary updated

BibTeX
@inproceedings{zhu2023efficient,
  author = {Hao Zhu and Yichen Li and Jie Li and Xiaofang Zhang},
  title = {{An Efficient Design Smell Detection Approach with Inter-class Relation (S)}},
  booktitle = {SEKE},
  year = {2023},
  url = {https://openreview.net/forum?id=GuRmRJSoMY},
}
Figure