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. Traits are composable pure units of behavior reuse, consisting only of methods, that have been proposed as an add-on to single class-based inheritance in order to improve reuse. However, adopting traits as an add-on to traditional class-based inheritance is not enough: classes, besides their primary role of generators of instances, still play the competing role of units of reuse. Therefore, a style of programming oriented to reuse is not enforced by the language, but left to the programmer’s skills. Traits have been originally proposed in the setting of dynamically typed language. 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, object oriented programming languages should be designed according to the principle that each software structuring construct must have exactly one role. We propose a realignment of the class-based object-oriented paradigm by presenting programming language features that separate completely the declarations of object type, behavior and generator. We illustrate our proposal through a core calculus and prove the soundness of the type system w.r.t. the operational semantics.
On Traits and Types in a Java-like Setting
BONO, Viviana;DAMIANI, Ferruccio;GIACHINO, Elena
2008-01-01
Abstract
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. Traits are composable pure units of behavior reuse, consisting only of methods, that have been proposed as an add-on to single class-based inheritance in order to improve reuse. However, adopting traits as an add-on to traditional class-based inheritance is not enough: classes, besides their primary role of generators of instances, still play the competing role of units of reuse. Therefore, a style of programming oriented to reuse is not enforced by the language, but left to the programmer’s skills. Traits have been originally proposed in the setting of dynamically typed language. 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, object oriented programming languages should be designed according to the principle that each software structuring construct must have exactly one role. We propose a realignment of the class-based object-oriented paradigm by presenting programming language features that separate completely the declarations of object type, behavior and generator. We illustrate our proposal through a core calculus and prove the soundness of the type system w.r.t. the operational semantics.I documenti in IRIS sono protetti da copyright e tutti i diritti sono riservati, salvo diversa indicazione.