Towards an Investigation of Opportunities for Refactoring to Design Patterns Norihiro Yoshida, Katsuro Inoue Osaka University Department of Computer Science, Graduate School of Information Science & Technology, Osaka University 1 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. Department of Computer Science, Graduate School of Information Science & Technology, Osaka University 2 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. Department of Computer Science, Graduate School of Information Science & Technology, Osaka University 3 An Example of Refactoring to Design Pattern Introduce Polymorphic Creation with Factory Method Condition 1 Before Refactoring junit::framework::TestCase DOMBuilderTest XMLBuilderTest testAddAboveRoot testAddAboveRoot Similar methods belong to classes that have a common parent class. Condition 2 ・・・ builder = new DOMBuilder(…); ・・・ Only difference among similar methods is an object creation step. ・・・ builder = new XMLBuilder(…); ・・・ Department of Computer Science, Graduate School of Information Science & Technology, Osaka University 4 An Example of Refactoring to Design Pattern Introduce Polymorphic Creation with Factory Method Before Refactoring After Refactoring junit::framework::TestCase junit::framework::TestCase AbstractBuilderTest #builder: OutputBuilder DOMBuilderTest XMLBuilderTest testAddAboveRoot It’s easy to addtestAddAboveRoot new test class. ・・・ builder = new DOMBuilder(…); ・・・ ・・・ builder = new XMLBuilder(…); ・・・ createBuilder testAddAboveRoot Factory Method: Creator ・・・ builder = new createBuilder(“orders”); ・・・ Factory Method: ConcreteCreator DOMBuilderTest XMLBuilderTest createBuilder createBuilder return new DOMBuilder(…); return new XMLBuilder(…); Department of Computer Science, Graduate School of Information Science & Technology, Osaka University 5 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 Department of Computer Science, Graduate School of Information Science & Technology, Osaka University 6 Automation of Identifying Opportunities Introduce Polymorphic Creation with Factory Method Condition 1 Before Refactoring junit::framework::TestCase Similar methods belong to classes that have a common parent class. Step 1 DOMBuilderTest XMLBuilderTest testAddAboveRoot testAddAboveRoot Detect similar methods using a code clone detection tool such as CCFinder Condition 2 ・・・ builder = new DOMBuilder(…); ・・・ ・・・ builder = new XMLBuilder(…); ・・・ Only difference among similar methods is an object creation step. Step 2 Evaluate whether detected methods include object creation statements Department of Computer Science, Graduate School of Information Science & Technology, Osaka University 7 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 Department of Computer Science, Graduate School of Information Science & Technology, Osaka University 8 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 Department of Computer Science, Graduate School of Information Science & Technology, Osaka University 9
© Copyright 2024 ExpyDoc