Traits: Composable Units of Behavior

Schärli, Nathanael; Ducasse, Stéphane; Nierstrasz, Oscar; Black, Andrew P. (2002). Traits: Composable Units of Behavior Universität Bern, Switzerland: Universität Bern

[img] Text
Scha02bTraits.pdf - Published Version
Restricted to registered users only
Available under License Publisher holds Copyright.

Download (251kB) | Request a copy

Inheritance is the fundamental reuse mechanism in object-oriented programming languages; its most prominent variants are single inheritance, multiple inheritance, and mixin inheritance. In the first part of this paper, we identify and illustrate the conceptual and practical reusability problems that arise with these forms of inheritance. We then present a simple compositional model for structuring object-oriented programs, which we call traits. Traits are essentially groups of methods that serve as building blocks for classes and are primitive units 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 with 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.

Item Type:

Report (Report)


08 Faculty of Science > Institute of Computer Science (INF)
08 Faculty of Science > Institute of Computer Science (INF) > Software Composition Group (SCG)

UniBE Contributor:

Ducasse, Stephane and Nierstrasz, Oscar Marius


000 Computer science, knowledge & systems
500 Science > 510 Mathematics


Universität Bern




Manuela Bamert

Date Deposited:

22 Nov 2017 16:09

Last Modified:

11 Nov 2019 18:50

Additional Information:

Also available as Technical Report CSE-02-014, OGI School of Science & Engineering, Beaverton, Oregon, USA




Actions (login required)

Edit item Edit item
Provide Feedback