Separating Type, Behavior, and State to Achieve Very Fine-grained Reuse

Recently, Scharli et al. pointed out that both single and multiple class-based inheritance are often inappropriate as a reuse mechanism, because classes play two competing roles, namely, a class is both a generator of instances and a unit of reuse. To overcome this problem, Scharli et al. proposed traits, which are composable pure units of behavior reuse consisting only of methods. However, both in the original proposal and (to the best of our knowledge) in all the trait-based approaches that can be found in the literature, traits live together with the traditional class-based inheritance. Therefore, besides their primary role of generators of instances, classes can still play a secondary role of units of (state and behavior) reuse, and a style of programming oriented to reuse is not enforced by the language, but left to the programmer’s skills. When static typing is also taken into account, the role of unit of reuse and the role of type are competing, too. We argue that, in order to support the development of reusable program components, class-based statically typed programming languages should be designed according to the principle that each programming construct must have exactly one role. We present language constructs that separate completely the declarations of object type, behavior, state, and generator.

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

[2]  Davide Ancona,et al.  Jam---designing a Java extension with mixins , 2003, TOPL.

[3]  Oscar Nierstrasz,et al.  Flattening Traits , 2006, J. Object Technol..

[4]  Donna Malayeri Combining structural subtyping and external dispatch , 2007, OOPSLA Companion.

[5]  M A R C V A N L I M B E R G H E N,et al.  Encapsulation and composition as orthogonal operators on mixins: a solution to multiple inheritance problems , 1996 .

[6]  Kent L. Beck,et al.  Extreme programming explained - embrace change , 1990 .

[7]  Craig Larman,et al.  Applying UML and Patterns: An Introduction to Object-Oriented Analysis and Design and Iterative Development (3rd Edition) , 1997 .

[8]  Oscar Nierstrasz,et al.  Stateful Traits , 2006, ISC.

[9]  John H. Reppy,et al.  Inheritance-Based Subtyping , 2002, Inf. Comput..

[10]  Philip Wadler,et al.  Featherweight Java: a minimal core calculus for Java and GJ , 2001, TOPL.

[11]  Matthias Felleisen,et al.  Classes and mixins , 1998, POPL '98.

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

[13]  Mariangiola Dezani-Ciancaglini,et al.  A filter lambda model and the completeness of type assignment , 1983, Journal of Symbolic Logic.

[14]  Oscar Nierstrasz,et al.  Traits: Composable Units of Behaviour , 2002, ECOOP.

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

[16]  Gilad Bracha,et al.  The programming language jigsaw: mixins, modularity and multiple inheritance , 1992 .

[17]  Alan Snyder Encapsulation and inheritance in object-oriented programming languages , 1986, OOPSLA 1986.

[18]  Eric G. Wagner Overloading and Inheritance , 1992, COMPASS/ADT.

[19]  Overloading and Inheritance , 2001 .

[20]  Jonathan Aldrich,et al.  Combining structural subtyping and external dispatch , 2007, OOPSLA '07.

[21]  Mariangiola Dezani-Ciancaglini,et al.  A new type assignment for λ-terms , 1978, Arch. Math. Log..

[22]  Atsushi Igarashi,et al.  Union types for object-oriented programming , 2006, SAC.

[23]  Tom Mens,et al.  Encapsulation and composition as orthogonal operators on mixins: a solution to multiple inheritance problems , 1996, Object Oriented Syst..

[24]  Craig Larman,et al.  Applying UML and Patterns: An Introduction to Object-Oriented Analysis and Design and the Unified Process , 2001 .

[25]  Aaron Turon,et al.  Metaprogramming with Traits , 2007, ECOOP.

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

[27]  Aaron Turon,et al.  A foundation for trait-based metaprogramming , 2005 .

[28]  William R. Cook,et al.  Inheritance is not subtyping , 1989, POPL '90.

[29]  Luigi Liquori,et al.  FeatherTrait: A modest extension of Featherweight Java , 2008, TOPL.