ECOOP 2003 – Object-Oriented Programming

Volume 2743 of the series Lecture Notes in Computer Science pp 248-274

Traits: Composable Units of Behaviour

  • Nathanael SchärliAffiliated withSoftware Composition Group, University of Bern
  • , Stéphane DucasseAffiliated withSoftware Composition Group, University of Bern
  • , Oscar NierstraszAffiliated withSoftware Composition Group, University of Bern
  • , Andrew P. BlackAffiliated withOGI School of Science & Engineering, Oregon Health and Science University

* Final gross prices may vary according to local VAT.

Get Access


Despite the undisputed prominence of inheritance as the fundamental reuse mechanism in object-oriented programming languages, the main variants—single inheritance, multiple inheritance, and mixin inheritance—all suffer from conceptual and practical problems. In the first part of this paper, we identify and illustrate these problems. We then present traits, a simple compositional model for structuring object-oriented programs. A trait is essentially a group of pure methods that serves as a building block for classes and is a primitive unit of code reuse. In this model, classes are composed from a set of traits by specifying glue code that connects the traits together and accesses the necessary state. We demonstrate how traits overcome the problems arising from the different variants of inheritance, we discuss how traits can be implemented effectively, and we summarize our experience applying traits to refactor an existing class hierarchy.


Inheritance mixins multiple inheritance traits reuse Smalltalk