Traits: The Formal Model

Nathanael Schärli, Oscar Nierstrasz, Stéphane Ducasse, Roel Wuyts, Andrew Black
Traits are reusable units of behaviour that provide a level of structuring for object-oriented programs above the level of methods but below the level of classes. Structuring classes with single-inheritance alone can lead to duplicated code when different branches of the hierarchy need to use the same feature. Multiple-inheritance and mixins alleviate this problem, but lead to other difficulties in the face of evolution: changes to classes or mixins can break code lower in the hierarchy in
more » ... ected ways. Traits solve both problems by factoring out shared behaviour as sets of methods that do not depend on state. Trait composition is symmetric and conflicts must be managed explicitly; this means that changes in the components do not lead to unexpected side effects. This paper presents a formal model of traits, and defines some basic properties of traits and classes. We also model the internal dependencies created by self and super-sends so that we can specify precisely when two classes are equivalent.
doi:10.7892/boris.104760 fatcat:5zwcmappybfihkt4tur46yqyw4