Automated refactoring of super-class method invocations to the Template Method design pattern

Abstract Context: Implementation inheritance, i.e., overriding of concrete method implementations through subtyping, is prone to potential class contract violations. Call Super is a code pattern that employs implementation inheritance for extending a method’s behaviour. In Call Super the overriding method includes in its body an invocation to the overridden method. Template Method is a design pattern that enables extensions to a multi-step procedure without overriding its concrete implementation. Instead, subclasses provide different variants of the template method’s behaviour through implementation of abstract method definitions (interface inheritance). Objective: This work studies the automated refactoring of Call Super to Template Method , contributing, thus, to replacement of implementation inheritance with interface inheritance. Method: We introduce an algorithm for the discovery of refactoring candidates that is based on an extensive set of refactoring preconditions. Moreover, we specify the source code transformation for refactoring a Call Super instance to Template Method . An implementation of the proposed approach is evaluated on a set of open source Java projects. Results: The evaluation results highlight (a) the frequent occurrence of the Call Super pattern among method overridings, (b) the potential provided by our method for discovery and elimination of several non-trivial Call Super instances and (c) the resulting code improvement, as reflected by the Specialization Index metric and the alignment of refactored code with the programmer’s intent. The application of all refactorings identified on a set of benchmark projects and the successful execution of their test suites provide empirical evidence on the soundness of the refactoring procedure. Runtime performance results support the scalability of the proposed method. Conclusion: The proposed method automates the replacement of implementation inheritance with interface inheritance through refactoring Call Super instances to Template Method . The empirical evaluation of the method supports its applicability, soundness and runtime efficiency.

[1]  Doo-Hwan Bae,et al.  An automated refactoring approach to design pattern-based program transformations in Java programs , 2002, Ninth Asia-Pacific Software Engineering Conference, 2002..

[2]  Sujeet Kumar,et al.  Java Agent Development Framework , 2014 .

[3]  Don Batory,et al.  Automated Software Evolution via Design Pattern Transformations , 1995 .

[4]  N. A. Diamantidis,et al.  Automated refactoring to the Null Object design pattern , 2015, Inf. Softw. Technol..

[5]  Robert C. Martin Agile Software Development, Principles, Patterns, and Practices , 2002 .

[6]  Houari A. Sahraoui,et al.  Search-Based Refactoring Using Recorded Code Changes , 2013, 2013 17th European Conference on Software Maintenance and Reengineering.

[7]  Foutse Khomh,et al.  Numerical Signatures of Antipatterns: An Approach Based on B-Splines , 2010, 2010 14th European Conference on Software Maintenance and Reengineering.

[8]  D. Janaki Ram,et al.  JIAD: a tool to infer design patterns in refactoring , 2004, PPDP '04.

[9]  Tom Mens,et al.  A survey of software refactoring , 2004, IEEE Transactions on Software Engineering.

[10]  Joshua Bloch Effective Java (2nd Edition) (The Java Series) , 2008 .

[11]  Claes Wohlin,et al.  Experimentation in software engineering: an introduction , 2000 .

[12]  Alan Snyder,et al.  Encapsulation and inheritance in object-oriented programming languages , 1986, OOPLSA '86.

[13]  Foutse Khomh,et al.  Evaluating the impact of design pattern and anti-pattern dependencies on changes and faults , 2015, Empirical Software Engineering.

[14]  Mel Ó Cinnéide,et al.  A methodology for the automated introduction of design patterns , 1999, Proceedings IEEE International Conference on Software Maintenance - 1999 (ICSM'99). 'Software Maintenance for Business Change' (Cat. No.99CB36360).

[15]  Ladan Tahvildari,et al.  A metric-based approach to enhance design quality through meta-pattern transformations , 2003, Seventh European Conference onSoftware Maintenance and Reengineering, 2003. Proceedings..

[16]  Marouane Kessentini,et al.  Search-Based Refactoring Detection Using Software Metrics Variation , 2013, SSBSE.

[17]  Vladimir Cretu,et al.  A logic based approach to locate composite refactoring opportunities in object-oriented code , 2010, 2010 IEEE International Conference on Automation, Quality and Testing, Robotics (AQTR).

[18]  Shinji Kusumoto,et al.  Identifying, Tailoring, and Suggesting Form Template Method Refactoring Opportunities with Program Dependence Graph , 2012, 2012 16th European Conference on Software Maintenance and Reengineering.

[19]  Ralph Johnson,et al.  design patterns elements of reusable object oriented software , 2019 .

[20]  Joshua Kerievsky,et al.  Refactoring to Patterns , 2004, XP/Agile Universe.

[21]  William G. Griswold,et al.  Automated support for program refactoring using invariants , 2001, Proceedings IEEE International Conference on Software Maintenance. ICSM 2001.

[22]  Yann-Gaël Guéhéneuc,et al.  DECOR: A Method for the Specification and Detection of Code and Design Smells , 2010, IEEE Transactions on Software Engineering.

[23]  Matthew Naylor,et al.  Finding Inputs that Reach a Target Expression , 2007 .

[24]  Mel Ó Cinnéide,et al.  Search-based refactoring: an empirical study , 2008 .

[25]  Leon Moonen,et al.  Java quality assurance by detecting code smells , 2002, Ninth Working Conference on Reverse Engineering, 2002. Proceedings..

[26]  Chris Parnin,et al.  A catalogue of lightweight visualizations to support code smell inspection , 2008, SOFTVIS.

[27]  Lionel C. Briand,et al.  Exploring the relationships between design measures and software quality in object-oriented systems , 2000, J. Syst. Softw..

[28]  H.,et al.  Behavioral Subtyping Using Invariants and ConstraintsBarbara , 1999 .

[29]  Andrew P. Black,et al.  An interactive ambient visualization for code smells , 2010, SOFTVIS '10.

[30]  Johannes Stammel,et al.  Search-based determination of refactorings for improving the class structure of object-oriented systems , 2006, GECCO.

[31]  Emmanouel A. Giakoumakis,et al.  Automated refactoring to the Strategy design pattern , 2012, Inf. Softw. Technol..

[32]  Radu Marinescu,et al.  Detection strategies: metrics-based rules for detecting design flaws , 2004, 20th IEEE International Conference on Software Maintenance, 2004. Proceedings..

[33]  Mark Lorenz,et al.  Object-oriented software metrics - a practical guide , 1994 .

[34]  Stéphane Ducasse,et al.  A language independent approach for detecting duplicated code , 1999, Proceedings IEEE International Conference on Software Maintenance - 1999 (ICSM'99). 'Software Maintenance for Business Change' (Cat. No.99CB36360).

[35]  Alexander Chatzigeorgiou,et al.  Evaluation and Improvement of Software Architecture: Identification of Design Problems in Object-Oriented Systems and Resolution through Refactorings , 2010 .

[36]  簡聰富,et al.  物件導向軟體之架構(Object-Oriented Software Construction)探討 , 1989 .

[37]  Béat Hirsbrunner,et al.  Toward an Implementation of the "Form Template Method" Refactoring , 2007, Seventh IEEE International Working Conference on Source Code Analysis and Manipulation (SCAM 2007).

[38]  Mark Kent O'Keeffe,et al.  Search-based refactoring for software maintenance , 2008, J. Syst. Softw..

[39]  Alexander Chatzigeorgiou,et al.  Identification of refactoring opportunities introducing polymorphism , 2010, J. Syst. Softw..

[40]  Foutse Khomh,et al.  An exploratory study of the impact of antipatterns on class change- and fault-proneness , 2011, Empirical Software Engineering.

[41]  Claus Lewerentz,et al.  Metrics Based Refactoring , 2001, CSMR.

[42]  Foutse Khomh,et al.  A Bayesian Approach for the Detection of Code and Design Smells , 2009, 2009 Ninth International Conference on Quality Software.

[43]  Bertrand Meyer,et al.  Object-oriented software construction (2nd ed.) , 1997 .

[44]  Tom Mens,et al.  Identifying refactoring opportunities using logic meta programming , 2003, Seventh European Conference onSoftware Maintenance and Reengineering, 2003. Proceedings..

[45]  Mauricio A. Saca Refactoring improving the design of existing code , 2017, 2017 IEEE 37th Central America and Panama Convention (CONCAPAN XXXVII).

[46]  Ladan Tahvildari,et al.  A Metric-Based Heuristic Framework to Detect Object-Oriented Design Flaws , 2006, 14th IEEE International Conference on Program Comprehension (ICPC'06).