Presentation is loading. Please wait.

Presentation is loading. Please wait.

MultiRefactor: Automated Refactoring To Improve Software Quality

Similar presentations


Presentation on theme: "MultiRefactor: Automated Refactoring To Improve Software Quality"— Presentation transcript:

1 MultiRefactor: Automated Refactoring To Improve Software Quality
Michael Mohan1 and Des Greer Queen’s University Belfast, Northern Ireland, UK

2 Search-Based Software Engineering
Search-Based Software Engineering Applies search-based optimization techniques to areas of software engineering. Optimization algorithms can be used to automate aspects of software engineering to improve efficiency. Has been applied to a range of areas across the software development process e.g. project planning, software design, maintenance, testing, error removal.

3 Search-Based Software Maintenance
Search-Based Software Maintenance Focuses on search-based software engineering applied to software maintenance. Involves refactoring of the software code itself to improve its structure and remove design defects. Search-based optimization algorithms can be used to refactor software and metrics can be used to inform the progress of the search. The area allows the software development process to be managed in a more agile way by reducing the time needed to maintain the code.

4 MultiRefactor A refactoring tool has been developed to automate maintenance in Java programs using search-based optimization techniques. The tool can be used for software development or for research. The tool contain 26 refactorings and 23 software metrics. MultiRefactor can be downloaded online at

5 Refactorings Available
Refactorings Available Field Level Method Level Class Level Increase Field Visibility Increase Method Visibility Make Class Final Decrease Field Visibility Decrease Method Visibility Make Class Non Final Make Field Final Make Method Final Make Class Abstract Make Field Non Final Make Method Non Final Make Class Concrete Make Field Static Make Method Static Extract Subclass Make Field Non Static Make Method Non Static Collapse Hierarchy Move Field Down Move Method Down Remove Class Move Field Up Move Method Up Remove Interface Remove Field Remove Method

6 Refactorings Available
Refactorings Available Mostly based on Martin Fowlers1 list of refactorings. Each refactoring checks the semantics of the software code before it is applied, to make sure the relevant element can be refactored. Refactorings have been constructed using the RECODER2 framework in order to modify an abstract syntax tree that represents the elements of the code. 1 2

7 Metrics Available QMOOD Based Metrics CK Based Metrics Others
Metrics Available QMOOD Based Metrics CK Based Metrics Others Class Design Size Weighted Methods Per Class Abstractness Number Of Hierarchies Number Of Children Abstract Ratio Average Number Of Ancestors Static Ratio Data Access Metric Final Ratio Direct Class Coupling Constant Ratio Cohesion Among Methods Inner Class Ratio Aggregation Referenced Methods Ratio Functional Abstraction Visibility Ratio Number Of Polymorphic Methods Lines Of Code Class Interface Size Number Of Files Number Of Methods

8 Metrics Available Metrics adapted taken from the QMOOD and CK metric suites. Other metrics also exist investigating structural aspects of the code. They can be combined to represent different configurations and can be given weights to cause differing influences on the search process. Different configurations of metrics can be used in different refactoring tasks to improve the software according to different priorities.

9 Search Techniques Available
Search Techniques Available Search Type Search Variation Random Search N/A Hill Climbing Search First-Ascent Steepest-Ascent Simulated Annealing Genetic Algorithm Simple Mono-Objective GA NSGA-II NSGA-III

10 Search Techniques Available
Search Techniques Available Metaheuristic algorithms have been developed for the tool using refactorings as the building blocks to enact change to the software. Three different types of genetic algorithm have been adapted for the tool: The basic algorithm uses refactorings to develop a population of solutions according to a single measure of quality. The multi-objective algorithm is adapted from NSGA-II and allows for the fitness of the solutions to be measured according to multiple different objectives. A many-objective algorithm is also available to successfully balance more than 3 objectives using the improved fitness calculations of NSGA-III.

11 Experimentation Experimentation was conducted with the tool to:
Experimentation Experimentation was conducted with the tool to: Deduce useful parameter settings to use with the genetic algorithms. Test the available metrics with the genetic algorithm. Compare the mono-objective genetic approach with the multi-objective genetic approach.

12 Experimentation There are 5 different configuration parameters that can be set in the genetic algorithm. They are tested using trial and error. Each metric is tested separately with the genetic algorithm using the parameter settings deduced from the previous trial and error experiment. The metrics are split into 3 groups to test as separate objectives with the mono-objective and multi-objective algorithms.

13 Input Programs Used Name Lines Of Code Classes mmohan03@qub.ac.uk
JSON 1.1 2,196 12 Mango 3,470 78 Beaver 6,493 70 Apache XML-RPC 2.0 11.616 79 JHotDraw 5.3 27,824 241

14 Comparison Of Parameter Settings
Comparison Of Parameter Settings First, the crossover and mutation probabilities are compared using a baseline metric and input. Nine different configuration combinations are tested and each task is repeated 5 times. Most improved configuration is with mutation probability of 0.8 and crossover probability of 0.2.

15 Comparison Of Parameter Settings
Comparison Of Parameter Settings Next, amount of generations, population size and refactoring range is tested using the mutation and crossover settings derived from before. 27 different tasks are set up. The task that gives the best balance of metric improvement and time taken to run is chosen.

16 Parameter Settings Used
Parameter Settings Used Configuration Parameter Value Crossover Probability 0.2 Mutation Probability 0.8 Generations 100 Refactoring Range 50 Population Size

17 Comparison Of Metrics Each of the 23 metrics are tested separately in a genetic algorithm and the metric improvements are compared. The more successful metrics are the ones measuring lower level aspects of the code. The 18 more volatile metrics are split into 3 individual objectives to be used in a multi-objective setup, with similarly volatile metrics being grouped together. Objectives are used as examples in order to test the multi-objective genetic algorithm. Objective 1 Objective 2 Objective 3 Class Interface Size Data Access Metric Aggregation Static Ratio Direct Class Coupling Functional Abstraction Final Ratio Cohesion Among Methods Number Of Polymorphic Methods Constant Ratio Number Of Methods Abstractness Weighted Methods Per Class Inner Class Ratio Abstract Ratio Lines Of Code Referenced Methods Ratio Visibility Ratio

18 Comparison Of Search Approaches
Comparison Of Search Approaches The mono-objective genetic algorithm is run 3 times with each of the objectives separately. The multi-objective algorithm is run with all 3 objectives in a combined approach. The best scores for each objective are averaged and compared across the 2 approaches. Although the mono-objective approach is better for 2 out of the 3 objectives, the multi-objective approach gives comparable scores for all 3 objectives.

19 Comparison Of Time Taken
Comparison Of Time Taken The multi-objective approach takes less time than each of the three mono-objective runs. Overall, the time taken to run all of the tasks with the multi-objective approach is 58.46% less than the time taken to run all the tasks with the 3 mono-objective runs.

20 Conclusion The MultiRefactor tool can be used to refactor Java code using a variety of different methods and contains numerous refactorings. The metrics in the tool were tested with the genetic algorithm and the most useful metrics were isolated. The mono-objective genetic algorithm was compared with the multi-objective algorithm and the objective scores were found to be comparable with both approaches, with the multi-objective approach taking less time.

21 Opportunities For Future Work
Opportunities For Future Work The tool can be used for further research with automated refactoring. Analysis of different refactorings and software metrics, as well as novel approaches to measuring software objectives, may provide additional assistance in the maintenance of software programs. A useful follow up to the experimentation would be to acquire the judgment of software developers on the refactored code and find out if their opinions line up with the metric analysis.

22 Email at: mmohan03@qub.ac.uk


Download ppt "MultiRefactor: Automated Refactoring To Improve Software Quality"

Similar presentations


Ads by Google