Using Traits as Aspects

Roel Wuyts

Université Libre de Bruxelles, Belgium

Abstract

Inheritance is well-known and accepted as a mechanism for reuse in object-oriented languages. Unfortunately, due to the coarse granularity of inheritance, it may be difficult to decompose an application into an optimal class hierarchy that maximizes software reuse. Existing schemes based on single inheritance, multiple inheritance, or mixins, each pose numerous problems for reuse. To overcome these problems, we propose traits, pure units of reuse consisting only of methods. Traits are a mechanism for building and structuring the classes in object-oriented programs. The same trait can be reused in many classes, irrespective of the position of those classes in the inheritance hierarchy. Traits can be manipulated using a set of operators---trait composition, overriding, exclusion, and aliasing---that are carefully designed so that they allow a fair amount of composition flexibility without being subject to the problems and limitations that we have identified for mixins and multiple inheritance. This talk introduces the traits model, shows examples of its application and relates it to aspects.