Systematically refactoring inheritance to delegation in java

Because of the strong coupling of classes and the proliferation of unneeded class members induced by inheritance, the suggestion to use composition and delegation instead has become common place. The presentation of a corresponding refactoring in the literature may lead one to believe that such a transformation is a straightforward undertaking. However, closer analysis reveals that this refactoring is neither always possible, nor does it necessarily achieve its desired effect. We have therefore identified the necessary preconditions and realizable postconditions of the refactoring, and built a tool that can perform it completely automatically. By applying this tool to all subclasses of several open-source projects, we have collected evidence of the applicability of the refactoring and of its capability to deliver on its promises. The refactoring builds on constraint graphs originally developed for type inference to check the preconditions and to compute the necessary delegation as well as the subtype relationships that must be maintained.

[1]  陈立兵 IntelliJ IDEA——开发人员利器 , 2009 .

[2]  Douglas C. Schmidt,et al.  Object-oriented application frameworks , 1997, CACM.

[3]  Oscar Nierstrasz,et al.  Traits: A mechanism for fine-grained reuse , 2006, TOPL.

[4]  Jens Palsberg,et al.  Object-oriented type inference , 1991, OOPSLA '91.

[5]  Benjamin C. Pierce,et al.  Types and programming languages: the next generation , 2003, 18th Annual IEEE Symposium of Logic in Computer Science, 2003. Proceedings..

[6]  Randall B. Smith,et al.  SELF: The power of simplicity , 1987, OOPSLA '87.

[7]  Brian Foote,et al.  Designing Reusable Classes , 2001 .

[8]  William R. Cook,et al.  Mixin-based inheritance , 1990, OOPSLA/ECOOP '90.

[9]  Raymie Stata,et al.  Modular reasoning in the presence of subclassing , 1995, OOPSLA.

[10]  Tom Mens,et al.  Design preservation over subsequent releases of a software product: a case study of Baan ERP: Practice Articles , 2005 .

[11]  Friedrich Steimann,et al.  ITCORE: A Type Inference Package for Refactoring Tools , 2007, WRT.

[12]  Serge Demeyer Analysis of Overridden Methods to Infer Hot Spots , 1998, ECOOP Workshops.

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

[14]  Franz J. Hauck,et al.  Inheritance modeled with explicit bindings: an approach to typed inheritance , 1993, OOPSLA '93.

[15]  Frank Tip,et al.  Efficiently Refactoring Java Applications to Use Generic Libraries , 2005, ECOOP.

[16]  Martin Fowler,et al.  Refactoring - Improving the Design of Existing Code , 1999, Addison Wesley object technology series.

[17]  Martin Fowler. Refactoring Improving the Design of Existing Code , 1999 .

[18]  M. Fowler Improving the Design of Existing Code , 2000 .

[19]  William F. Opdyke,et al.  Refactoring object-oriented frameworks , 1992 .

[20]  Henry Lieberman,et al.  Using prototypical objects to implement shared behavior in object-oriented systems , 1986, OOPLSA '86.

[21]  Tom Mens,et al.  Formalizing refactorings with graph transformations , 2005, J. Softw. Maintenance Res. Pract..

[22]  Emil Sekerinski,et al.  A Study of The Fragile Base Class Problem , 1998, ECOOP.

[23]  Frank Tip,et al.  Refactoring for generalization using type constraints , 2003, OOPSLA '03.

[24]  Friedrich Steimann,et al.  The Infer Type Refactoring and its Use for Interface-Based Programming , 2007, J. Object Technol..

[25]  Frank Tip,et al.  Refactoring for Parameterizing Java Classes , 2007, 29th International Conference on Software Engineering (ICSE'07).

[26]  Lynn Andrea Stein,et al.  Delegation is inheritance , 1987, OOPSLA '87.

[27]  Ralph E. Johnson,et al.  Refactoring and Aggregation , 1993, ISOTAS.

[28]  Gregor Snelting,et al.  Refactoring class hierarchies with KABA , 2004, OOPSLA '04.

[29]  Benedikt Schulz,et al.  Transforming inheritance into composition , 1999, EuroPLoP.

[30]  Guy L. Steele,et al.  The Java Language Specification , 1996 .

[31]  Daniel H. H. Ingalls A Simple Technique for Handling Multiple Polymorphism , 1986, OOPSLA.