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 class 或 Blob 是最常见的坏味之一。God class 包含太多的职责,违反了面向对象编程设计的高内聚低耦合原则。本文提出了一种自动的方法来将一个 God class 提取成多个更具体职责的小类。为了实现此目的,我们首先构建了 God class 方法的图形(作为节点)。两个方法之间的边缘是由它们的结构相似性确定的,每个方法的特征是使用不同的语义表示方法初始化的。然后,使用变分图自编码器学习每个方法的向量表示。最后,学习到的向量用于将方法聚类成不同的组以作为重构类的建议。我们在两个著名开源系统中收集的 16 个真实 God Classes 上使用了三种不同的类内聚度度量来评估所提出的框架。我们还对我们的方法进行了与现有方法的比较研究,并发现所提出的方法在实验中使用的几乎所有 God Classes 中都产生了更好的结果。