30
Recommending Refactoring Operations in Large Software Systems Pós Graduação em Ciência da Computação Aluno : Carlos Eduardo Dantas Orientador : Marcelo Maia

Recommending refactoring operations in large software systems

Embed Size (px)

DESCRIPTION

Presentation in FACOM seminary, in 15/09/2014.

Citation preview

Page 1: Recommending refactoring operations in large software systems

Recommending Refactoring Operations in Large

Software Systems

Pós Graduação em Ciência da ComputaçãoAluno: Carlos Eduardo DantasOrientador: Marcelo Maia

Page 2: Recommending refactoring operations in large software systems

Recommending Refactoring Operations in Large Software Systems

Introduction

• During its lifecycle, the internal structure of a Software system undergoes continuous modifications;

• Source code quality often decreases;

• Low quality is generally associated with lower productivity, more rework and more effort for developers.

Page 3: Recommending refactoring operations in large software systems

Recommending Refactoring Operations in Large Software Systems

Refactoring

• Process of changing Software System to improve its internal structure;

• Help in removing code bad smells as well as antipatterns;

• Improve Architeture and provide better Software extensibility.

Page 4: Recommending refactoring operations in large software systems

Recommending Refactoring Operations in Large Software Systems

Challenges on Refactoring code

• Design flaws are not always obvious;

• Its not easy to apply the correct refactoring operation to solve design problems;

• Apply the refactoring solution without changing the external behaviour of the system;

• Manual refactoring is an error-prone task.

Page 5: Recommending refactoring operations in large software systems

Recommending Refactoring Operations in Large Software Systems

Challenges on Refactoring code

• Refactoring recommendation systems supports:

Identifying refactoring opportunities;

Designing and applying a refactoring solution.

Page 6: Recommending refactoring operations in large software systems

Recommending Refactoring Operations in Large Software Systems

Refactoring operations catalog

• Some refactoring operations, classified on the benefits provided to the source code.

Improving Code Decomposition

Extract Class

Extract Package

Extract Method

Improving names and location of

code

Rename method (field)

Move method

Move class

Improving Conformance with

OOP principles

Push down field/method

Pull up field/method

Extract/collapse hierarchy

Page 7: Recommending refactoring operations in large software systems

Recommending Refactoring Operations in Large Software Systems

Algorithms exploited to identify refactoring recommendations

Refactoring Operation Approach

Extract Class Clustering-based or Graph-based

Move Method Heuristic-based or Search-based

Extract Method Slicing-based

Extract Package Graph-based

Move Class Search-based or Heuristic-based

Combination of multiple operations Search-based

• This presentation will discuss only Extract Class Refactoring approaches.

Page 8: Recommending refactoring operations in large software systems

Recommending Refactoring Operations in Large Software Systems

Extract Class Refactoring

• In OOP design, classes are called “God Class”, “System Class” or “Blob Class” when become very large, less cohesive and exhibit high levels of coupling;

• Class should implement only one concept, having only one reason to change;

• Extract class split the responsabilities implemented on Blob classes into different classes with higher cohesion.

Page 9: Recommending refactoring operations in large software systems

Recommending Refactoring Operations in Large Software Systems

Extract Class Refactoring with Clustering-Based algorithm

• Clustering methods can identify conceptually meaningful groups of similar entities;

• Clusters may represent cohesive groups of class members;

• Clusters compute an entity set for each attribute and invoke method.

Page 10: Recommending refactoring operations in large software systems

Recommending Refactoring Operations in Large Software Systems

Clustering-Based algorithm –extract entities

Page 11: Recommending refactoring operations in large software systems

Recommending Refactoring Operations in Large Software Systems

Clustering-Based algorithm –entity set

a1

name

changeJob

modifyName

getTelephoneNumber

a2

job

changeJob

modifyName

getTelephoneNumber

a3

officeAreaCode

getTelephoneNumber

a4

officeNumber

getTelephoneNumber

m1

changeJob

job

name

m2

modifyName

job

name

m3

getTelephoneNumber

job

name

officeAreaCode

officeAreaNumber

Page 12: Recommending refactoring operations in large software systems

Recommending Refactoring Operations in Large Software Systems

Clustering-Based algorithm –Jaccard method

• Jaccard method calculate the distance between entities, generating distance matrix.

Page 13: Recommending refactoring operations in large software systems

Recommending Refactoring Operations in Large Software Systems

Clustering-Based algorithm –cluster deondrogram

• Cluster´s hierarchy is usually represented by a deondrogram.

Page 14: Recommending refactoring operations in large software systems

Recommending Refactoring Operations in Large Software Systems

Clustering-Based algorithm –Evaluation

Software Total Suggestions Assigned Names Applied

eRisk 37 28 16

SelfPlanner 14 12 9

Page 15: Recommending refactoring operations in large software systems

Recommending Refactoring Operations in Large Software Systems

Graph-Based algorithm –class extraction process

• The candidate class is parsed to build a method-by-method matrix;

• NxN matrix where n is the number of methods of class to be refatored;

• Each entry represents the likelihood that method mi and method mj should be in the same class;

• Identify chains of strongly related or coupled methods.

Page 16: Recommending refactoring operations in large software systems

Recommending Refactoring Operations in Large Software Systems

Graph-Based algorithm –class extraction process

Page 17: Recommending refactoring operations in large software systems

Recommending Refactoring Operations in Large Software Systems

Graph-Based algorithm Method-by-method matrix

• Structural Similarity between Methods;

• Call-based dependence between methods;

• Conceptual similarity between methods.

Page 18: Recommending refactoring operations in large software systems

Recommending Refactoring Operations in Large Software Systems

Graph-Based algorithmMethod-by-method matrix

Page 19: Recommending refactoring operations in large software systems

Recommending Refactoring Operations in Large Software Systems

Graph-Based algorithmIdentifying candidate chains

Constant Threshold

Variable Threshold

Page 20: Recommending refactoring operations in large software systems

Recommending Refactoring Operations in Large Software Systems

Graph-Based algorithm –Evaluation

• Created an artificial scenario, where classes with high cohesion of five open source systems have been merged to build classes with low cohesion and many responsibilities

Page 21: Recommending refactoring operations in large software systems

Recommending Refactoring Operations in Large Software Systems

Graph-Based algorithm –Evaluation

• Constant threshold (0.1,0.2,0.3,0.4)

Page 22: Recommending refactoring operations in large software systems

Recommending Refactoring Operations in Large Software Systems

Graph-Based algorithm –Evaluation

• Variable threshold (Q1,Q2,Q3)

Page 23: Recommending refactoring operations in large software systems

Recommending Refactoring Operations in Large Software Systems

Graph-Based algorithm –Evaluation

• Interaction between weight and variable threshold on JHotDraw merging 2 classes

Page 24: Recommending refactoring operations in large software systems

Recommending Refactoring Operations in Large Software Systems

Graph-Based algorithm –Evaluation

• Interaction between weight and variable threshold on JHotDraw merging 3 classes

Page 25: Recommending refactoring operations in large software systems

Recommending Refactoring Operations in Large Software Systems

Graph-Based algorithm –Evaluation

• Interaction between weight and system merging 2 classes

Page 26: Recommending refactoring operations in large software systems

Recommending Refactoring Operations in Large Software Systems

Graph-Based algorithm –Evaluation

• Interaction between weight and system merging 3 classes

Page 27: Recommending refactoring operations in large software systems

Recommending Refactoring Operations in Large Software Systems

References

• [1] Robillard, Martin P.:, Maalej, Wallid.: Recommendation Systems in Software Engineering. Springer, 2014;

• [2] Fokaefs, M., Tsantalis, N., Chatzigeorgiou, A., Sander, J.: Decomposing object-oriented class modules using an agglomerative clustering technique. In: Proceedings of the IEEE International Conference on Software Maintenance, (2009);

• [3] Fowler, M.: Refactoring: improving the design of existing code. Addison-Wesley, Reading, 1999;

Page 28: Recommending refactoring operations in large software systems

Recommending Refactoring Operations in Large Software Systems

References

• [4] Fokaefs, M., Tsantalis, N., Stroulia, E., Chatzigeorgiou, A.: Identification and application of extract class refactorings in object-oriented systems. J. Syst. Software 85(10), 2012;

• [5] Bavota, G., De Lucia, A., Marcus, A., Oliveto, R.: Automating extract class refactoring: a Novel Approach and its Evaluation, 2011;

• [6] Bavota, G., De Lucia, A., Marcus, A., Oliveto, R.: In Medio Stat Virtus: Extract Class Refactoring through Nash Equilibria, 2011.

Page 29: Recommending refactoring operations in large software systems

Recommending Refactoring Operations in Large Software Systems

Appendix – Another Graph-Based algorithm example

Method Instance variables

changeJob {job,name}

modifyName {job,name}

getTelephoneNumber {job,name,officeAreaCode,officeNumber}

CJ MN GT

CJ 1 1 0,5

MN 1 1 0,5

GT 0,5 0,5 1

Method Call methods

changeJob {}

modifyName {}

getTelephoneNumber {}

CJ MN GT

CJ 1 1 0

MN 0 1 0

GT 0 0 1

Method Conceptual Similarity

changeJob {}

modifyName {}

getTelephoneNumber {}

CJ MN GT

CJ 1 0.7 0.1

MN 0.7 1 0.1

GT 0.1 0.1 1

Page 30: Recommending refactoring operations in large software systems

Recommending Refactoring Operations in Large Software Systems

Appendix – Another Graph-Based algorithm example

CJ MN GT

CJ 1 0.7 0.2

MN 0.7 1 0.2

GT 0.2 0.2 1