120 likes | 259 Views
Towards an Assessment of the Quality of Refactoring Patterns. Norihiro Yoshida , Masatomo Yoshida, Katsuro Inoue Osaka University, Japan. Refactoring . Refactoring is a process of restructuring an existing code.
E N D
Towards an Assessment of the Quality of Refactoring Patterns Norihiro Yoshida, Masatomo Yoshida, Katsuro Inoue Osaka University, Japan
Refactoring • Refactoring is a process of restructuring an existing code. • Alter software’s internal structure without changing its external behavior • Improve the maintainability of software • Example of Refactoring • Merging code clones into a new method New method Call statements
Refactoring Pattern • Typical process of restructuring existing code • Extract Method, Pull Up Method, Extract Class • Each refactoring pattern includes • refactoring opportunity (bad smell) • a set of code fragments that should be refactored • procedure to perform refactoring • how to perform refactoring
Literatures for Refactoring Patterns • A lot of refactoring patterns are proposed in several literatures. • M. Fowler, Refactoring: improving the design of existing code. Addison Wesley, 1999. • M. Fowler, http://refactoring.com/(93 patterns) • J. Kerievsky, Refactoring to Patterns. Addison Wesley, 2004. (27 patterns) However, the quality of each refactoring pattern is mostly never assessed.
Overview of Our Research • Propose the following quality characteristics of refactoring patterns • Number of Refactoring Opportunities • Ease of Refactoring • Perform a case study on assessing those quality characteristics • A case study on Introduce Polymorphic Creation with Factory Method [1] that is a kind of Pull Up Method [1] J. Kerievsky, Refactoring to Patterns. Addison Wesley, 2004
Propose Quality Characteristics of Refactoring Patterns • Number of Refactoring Opportunities • What kind of refactoring opportunities are involved in software systems? • Ease of Refactoring • It means that ease of applying each refactoring pattern to refactoring opportunities in source code. • We focus on “Whether or not each refactoring pattern involves enough description to perform refactoring easily”.
Case StudyTarget Refactoring Pattern (1/2) • We assess the quality characteristics of Introduce Polymorphic Creation with Factory Method. Before Refactoring junit::framework::TestCase Condition 1 Similar methods belong to classes that have a common parent class. DOMBuilderTest XMLBuilderTest testAddAboveRoot testAddAboveRoot Condition 2 Only difference among similar methods is an object creation step. ・・・ builder = new DOMBuilder(…); ・・・ ・・・ builder = new XMLBuilder(…); ・・・
Case StudyTarget Refactoring Pattern (2/2) • We assess the quality characteristics of Introduce Polymorphic Creation with Factory Method. Before Refactoring After Refactoring junit::framework::TestCase junit::framework::TestCase Factory Method: Creator AbstractBuilderTest #builder: OutputBuilder ・・・ builder = new createBuilder(“orders”); ・・・ DOMBuilderTest XMLBuilderTest createBuilder It’s easy to add new test class. testAddAboveRoot testAddAboveRoot testAddAboveRoot Factory Method: ConcreteCreator ・・・ builder = new DOMBuilder(…); ・・・ DOMBuilderTest XMLBuilderTest createBuilder createBuilder ・・・ builder = new XMLBuilder(…); ・・・ return new DOMBuilder(…); return new XMLBuilder(…);
Case StudyAutomation of Identifying Opportunities • We developed an automated tool that identifies opportunities. Condition 1 Similar methods belong to classes that have a common parent class. Before Refactoring junit::framework::TestCase Step 1 Detect similar methods using a code clone detection tool CCFinder DOMBuilderTest XMLBuilderTest testAddAboveRoot testAddAboveRoot Condition 2 Only difference among similar methods is an object creation step. ・・・ builder = new DOMBuilder(…); ・・・ Step 2 Evaluate whether detected methods include object creation statements ・・・ builder = new XMLBuilder(…); ・・・
Case StudyNumber of Refactoring Opportunities 17.9% of the refactoring opportunities for Pull Up Methodare also for Introduce Polymorphic Creation with Factory Method. Developers should inspect whether refactoring opportunities for Pull Up Methodare also are also for Introduce Polymorphic Creation with Factory Method.
Case StudyEase of Refactoring • Apply the target pattern to the refactoring opportunities in Ant and ANTLR. • Confirm the steps that are not described in the description of the target pattern. We did not have to apply additional steps that are not described in the description of the target pattern. In terms of the ease of refactoring, the quality of the pattern presentation is enough.
Summary & Future Work • Summary • Two quality characteristics of refactoring patterns • A case study on assessing those quality characteristics • Future Work • Assess other refactoring patterns • To compare refactoring patterns in terms of proposed quality characteristics • Discuss change in maintainability