90 likes | 255 Vues
Towards an Investigation of Opportunities for Refactoring to Design Patterns. Norihiro Yoshida , Katsuro Inoue Osaka University. Refactoring. Refactoring is a technique for restructuring an existing code[1]. Alter software’s internal structure without changing its external behavior
E N D
Towards an Investigation of Opportunities for Refactoring to Design Patterns Norihiro Yoshida, Katsuro Inoue Osaka University
Refactoring • Refactoring is a technique for restructuring an existing code[1]. • Alter software’s internal structure without changing its external behavior • Improve the maintainability of software • We have worked on refactoring support for code clone. New method Call statements [1] M. Fowler, Refactoring: improving the design of existing code, Addison Wesley, 1999.
Refactoring to Design Patterns • Improve design quality of software that lack of design patterns • J. Kerievsky, Refactoring to Patterns, Addison Wesley, 2004. • 27 refactoring patterns • Refactoring opportunity • Procedure for performing refactoring using design pattern • J. Rajesh et al., JIAD: A tool to infer design patterns in refactoring, PPDP 2004. • M. O. Cinneide et al., A Methodology for the Automated Introduction of Design Patterns, ICSM 1999.
An Example of Refactoring to Design Pattern • Introduce Polymorphic Creation with Factory Method Condition 1 Similar methods belong to classes that have a common parent class. Before Refactoring junit::framework::TestCase DOMBuilderTest XMLBuilderTest testAddAboveRoot testAddAboveRoot Condition 2 Only difference among similar methods is an object creation step. ・・・ builder = new DOMBuilder(…); ・・・ ・・・ builder = new XMLBuilder(…); ・・・
An Example of Refactoring to Design Pattern • 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(…);
Our Research Question and Plan • Research Question • What kind of refactoring opportunities are involved in software systems? • Research Plan • Develop an automated tool that identifies opportunities • Carry out the investigation using the tool
Automation of Identifying Opportunities • Introduce Polymorphic Creation with Factory Method 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 such as 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(…); ・・・
Investigation points and Anticipated Results • Investigation points • How many refactoring opportunities exist? • Is it possible to improve maintainability by performing refactoring to design patterns? • Anticipated Results • Quality differences among design patterns • A number of refactoring opportunities • The degree of change in the maintainability
Summary and Current Status • We show a plan for investigating opportunities for refactoring to design patterns. • The automated tool that identifies opportunities for refactoring to design patterns • Our investigation points and anticipated results • We are currently investigating ANTLR. • ANTLR 2.7.4 (47,000 LOC, 285 Classes) • Open source compiler-compiler • Our tool detected 16 opportunities in ANTLR