The code smell is a sign of design and development flaws in a software system that reduces the reusability and maintainability of the system. Refactoring is done as an ongoing practice to remove the code smell from the program code. Among different code smells, the God class or Blob is one of the most common code smells. A god class contains too many responsibilities, violating object-oriented programming design's low coupling and high cohesiveness principles. This paper proposes an automatic approach to extracting a God class into multiple smaller classes with more specific responsibilities. To do this, we first construct a graph of methods (as nodes) for the concerning god class. The edge between any two methods is determined by their structural similarity, and the feature for each method is initialized using different semantic representation methods. Then, the variational graph auto-encoder is used to learn a vector representation for each method. Finally, the learned vectors are used to cluster methods into different groups to be recommended as refactored classes. We assessed the proposed framework using three different class cohesion metrics on sixteen actual God Classes collected from two well-known open-source systems. We also conducted a comparative study of our approach with a similar existing approach and found that the proposed approach generated better results for almost all the God Classes used in the experiment.
翻译:代码异味是软件系统中设计和开发缺陷的标志,会降低系统的可重用性和可维护性。重构作为一种持续实践,用于从程序代码中消除代码异味。在不同类型的代码异味中,上帝类(God类)或Blob是最常见的一种。上帝类包含过多职责,违反了面向对象编程设计中低耦合和高内聚的原则。本文提出了一种自动方法,将上帝类拆分为多个职责更明确的小类。为此,我们首先为目标上帝类构建一个方法图(以方法为节点)。任意两个方法之间的边由其结构相似性决定,每个方法的特征则使用不同的语义表示方法进行初始化。接着,利用变分图自编码器学习每个方法的向量表示。最后,将学习到的向量用于将方法聚类为不同分组,以推荐为重构后的类。我们使用三种不同的类内聚度量指标,对从两个知名开源系统中收集的16个实际上帝类评估了所提框架。我们还与现有类似方法进行了对比研究,发现所提方法在实验中使用的几乎所有上帝类上均产生了更优的结果。