Traits: Composable Units of Behaviour

  • Nathanael Schärli
  • Stéphane Ducasse
  • Oscar Nierstrasz
  • Andrew P. Black
Conference paper

DOI: 10.1007/978-3-540-45070-2_12

Part of the Lecture Notes in Computer Science book series (LNCS, volume 2743)
Cite this paper as:
Schärli N., Ducasse S., Nierstrasz O., Black A.P. (2003) Traits: Composable Units of Behaviour. In: Cardelli L. (eds) ECOOP 2003 – Object-Oriented Programming. ECOOP 2003. Lecture Notes in Computer Science, vol 2743. Springer, Berlin, Heidelberg

Abstract

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.

Keywords

Inheritance mixins multiple inheritance traits reuse Smalltalk 

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

Copyright information

© Springer-Verlag Berlin Heidelberg 2003

Authors and Affiliations

  • Nathanael Schärli
    • 1
  • Stéphane Ducasse
    • 1
  • Oscar Nierstrasz
    • 1
  • Andrew P. Black
    • 2
  1. 1.Software Composition GroupUniversity of BernSwitzerland
  2. 2.OGI School of Science & EngineeringOregon Health and Science University 

Personalised recommendations