Font Size: a A A

Research On Code Smells Detection Approach And Refactoring Analysis

Posted on:2015-03-26Degree:DoctorType:Dissertation
Country:ChinaCandidate:D X JiangFull Text:PDF
GTID:1108330479978681Subject:Computer application technology
Abstract/Summary:PDF Full Text Request
Code bad smells are the guard signals of potential problems. Bad smells would decrease the design quality of programs, and programs would be difficult to understand, modify or reuse. The bad smells detection of programs is the assessment reference of programs design quality. Meanwhile the detection is also the precondition and basis of bad smells improvements. After bad smells detection, the refactorings are needed to remove bad smells on the premise of unchanging observable behaviors, and the understandibility and expandability of programs are increased to improve the total quality of programs.In this paper a kind of bad smells are defined as Classes Over-Couple to describe the common pestilent phenomenon about confused inheritances. The bad smells about inheritance, cohesion, scale factors are detected as following: the characteristics of these bad smells are analysed and quantified to extract the metrics computing formulas, and the valued results are judged to achieve the bad smells detection. Then the correct refactoring is provided to deal with the results of detected bad smells. Furthermore the refactoring is evaluated effectively for executing. Through the researches of bad smells detection and providing refactoring, it is able to analyze the programs quality and remove the bad smells, and finally the goal of programs quality improvement is achieved.In object-oriented programs, usually the attributes and methods in different classes are too interconnected, and the inheritance relationships of these classes are confused. This leads to a new bad smell: Classes Over-Couple(COC). The difference and relationship of this bad smell and other existed bad smells are described. The expressions and damage of this bad smell are analyzed. Classes Over-Couple is classified as direct over-couple and indirect over-couple ones. On this basis bad smell dectection tool “COC Detector” is produced based on entities dependency relationships quantification, and the corresponding refactoring can be provide. Experimental results show that the codes with inheritance confusion can be expressed by this new bad smell Classes Over-Couple. COC Detector has the ability to dectect COC bad smells. Meanwhile, after the assesing of Quality Model for Object-Oriented Design, the refactoring is able to improve the total design quality of programs.The bad smells caused by low cohesion are analyzed and bad smells detection approach based on distance metrics and clustering analysis is proposed. This approach can give proper refactoring to deal with detected bad smells. Divergent Change bad smell is analyzed, and the bad smell characteristics are extracted as invoking relationships between entities, and then they are translated as distance values of entities. With the distance values, the entities in the classes are divided into several groups by K nearest neighbor clustering algorithm. In the bad smells caused by low cohesion in classes and high coupling among classes, the traditional detection methods have the problem of low accuracy, because they do not consider repeatedly invoking among entities. Therefore, weighted distance metric is defined, and the bad smell detection approach based on weighted distance metrics is proposed. This approach can provide refactoring for detected bad smells. Experimental results show that, after common bad smell detection tool comparison, the bad smell detection approach in this paper can detect Divergent Chang, Feature Envy and other smells more accurately, and the refactoring operations are closer to actual results.The scale distribution of classes in open source object-oriented programs is counted and analyzed, and the rule of class length distribution is discovered from experimental studies. Then the rule is proved. Based on this distribution rule, one Class Length Distribution Model(CLDM) is built for Large Class bad smell detection, and the corresponding refactoring operations can be provided. In Class Length Distribution Model, all the classes are dividing into groups. The group far away from the curve is considered as potential Large Class bad smell. In these groups, the cohesion metric of the class is defined and computed for bad smell judging. After detection, the agglomerative clustering is used for refactoring providing. Experimental results show that the program statistics distribution of a large number of open sources programs conforms well to the distribution rule. This proves the correctness of the theorem. After Large Class bad smell detection to open source programs with CLDM tool, the accuracy is higher than traditional Large Class detection tools PMD and Checkstyle, which use fixed thresholds for detection. Afer multiple versions comparison technology, the refactoring provided by CLDM have high accuracy.The effects of refactoring in income and cost are analyzed, and the refactoring evaluation approach based on Return On Refactoring Investment is proposed. Return On Refactoring Investment(RORI) is defined to analyze and evaluate the results and effect of refactoring operations. Aftere the benefits and cost quantification of refactoring, the computing formula of RORI is constructed. The refactoring should be executed earlier, if its RORI value is larger. Furthermore, if several refactoring operations can deal with the same bad smell, the one with larger RORI value should be executed. So the RORI can help deciding whether to execute one refactoring operation, or which refactoring operation should be executed. Experimental results show that after multiple versions comparison, when there are bad smells in programs and their refactoring operations have been confirmed, the refactoring operations with higher RORI have been executed in later versions. This shows the correctness of RORI. And after comparison with other refactoring evaluation methods, RORI based approach is more effective.In conclusion, in this paper Classes Over-Couple is confirmed, and the theories of weighted based distance, class length distribution rule, Return On Refactoring Investment are proposed, and the technologies of entities dependency relationships computing, clustering analysis, curve fitting are used for refactoring oriented code bad smells detection approach. This approach can detect bad smells and provide refactoring. These approachs effectively improve the researches of bad smells expressions, detections and refactoring.
Keywords/Search Tags:bad smell detection, bad smell refactoring, classes over-couple, cohesion metrics, refactoring income evaluation
PDF Full Text Request
Related items