Separating Type, Behavior, and State to Achieve Very Fine-grained Reuse
Viviana Bono, Ferruccio Damiani, Elena Giachino · Institutional Research Information System University of Turin (University of Turin) · 2007
Abstract. Recently, Schärli 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, Schärli 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. Keywords. Inheritance, Trait, Subtyping, Flattening. 1