Inproceedings,

Traits: Composable Units of Behavior

, , , and .
ECOOP 2003 -- Object-Oriented Programming, volume 2743/2003 of Lecture Notes in Computer Science, page 327--339. OGI School of Science & Engineering , Oregon Health and Science University, Springer, (November 2003)
DOI: 10.1007/b11832

Abstract

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.

Tags

Users

  • @gron

Comments and Reviews