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 Superinstances 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.
Talk to us
Join us for a 30 min session where you can share your feedback and ask us any queries you have