Skip to main content

Traits: Composable Units of Behaviour

  • Conference paper
ECOOP 2003 – Object-Oriented Programming (ECOOP 2003)

Part of the book series: Lecture Notes in Computer Science ((LNCS,volume 2743))

Included in the following conference series:

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.

This research was partially supported by the National Science Foundation under award CCR-0098323.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 84.99
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 109.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. Achermann, F., Nierstrasz, O.: Explicit Namespaces. In: Weck, W., Gutknecht, J. (eds.) JMLC 2000. LNCS, vol. 1897, pp. 77–89. Springer, Heidelberg (2000)

    Chapter  Google Scholar 

  2. America, P.: Designing an object-oriented programming language with behavioural subtyping. In: Proceedings REX/FOOLS Workshop, Noordwijkerhout (June 1990)

    Google Scholar 

  3. Ancona, D., Lagorio, G., Zucca, E.: Jam - a smooth extension of java with mixins. In: Bertino, E. (ed.) ECOOP 2000. LNCS, vol. 1850, pp. 145–178. Springer, Heidelberg (2000)

    Google Scholar 

  4. Bergel, A., Ducasse, S., Wuyts, R.: Classboxes: A minimal module model supporting local rebinding. In: Proceedings of the Joint Modular Languages Conference 2003. Springer, Heidelberg (2003) (to appear)

    Google Scholar 

  5. Black, A., Hutchinson, N., Jul, E., Levy, H.: Object structure in the Emerald system. In: Proceedings OOPSLA 1986, ACM SIGPLAN Notices, vol. 21, pp. 78–86 (November 1986)

    Google Scholar 

  6. Black, A., Schärli, N., Ducasse, S.: Applying traits to the Smalltalk collection hierarchy. Technical Report IAM-02-007, Institut für Informatik, Universität Bern, Switzerland (November 2002), Also available as Technical Report CSE-02-014, OGI School of Science & Engineering, Beaverton, Oregon, USA

    Google Scholar 

  7. Borning, A.H., Ingalls, D.H.H.: Multiple inheritance in Smalltalk-80. In: Proceedings at the National Conference on AI, Pittsburgh, PA (1982)

    Google Scholar 

  8. Bouraqadi-Saadani, N.M.N., Ledoux, T., Rivard, F.: Safe metaclass programming. In: Proceedings OOPSLA 1998, pp. 84–96 (1998)

    Google Scholar 

  9. Bracha, G.: The Programming Language Jigsaw: Mixins, Modularity and Multiple Inheritance. Ph.D. thesis, Dept. of Computer Science, University of Utah (March 1992)

    Google Scholar 

  10. Bracha, G., Cook, W.: Mixin-based inheritance. In: Proceedings OOPSLA/ ECOOP 1990, ACM SIGPLAN Notices, October 1990, vol. 25, pp. 303–311 (1990)

    Google Scholar 

  11. Cook, S.: OOPSLA 1987 Panel P2: Varieties of inheritance. In: OOPSLA 1987 Addendum To The Proceedings, pp. 35–40. ACM Press, New York (1987)

    Google Scholar 

  12. Cook, W.R.: Interfaces and specifications for the Smalltalk-80 collection classes. In: Proceedings OOPSLA 1992, ACM SIGPLAN Notices, vol. 27, pp. 1–15 (October 1992)

    Google Scholar 

  13. Curry, G., Baer, L., Lipkie, D., Lee, B.: TRAITS: an approach to multiple inheritance subclassing. In: Proceedings ACM SIGOA, Newsletter, vol. 3, Philadelphia (June 1982)

    Google Scholar 

  14. Dixon, R., McKee, T., Vaughan, M., Schweizer, P.: A fast method dispatcher for compiled languages with multiple inheritance. In: Proceedings OOPSLA 1989, ACM SIGPLAN Notices, vol. 24, pp. 211–214 (October 1989)

    Google Scholar 

  15. Ducournau, R., Habib, M., Huchard, M., Mugnier, M.L.: Monotonic conflict resolution mechanisms for inheritance. In: Proceedings OOPSLA 1992, ACM SIGPLAN Notices, vol. 27, pp. 16–24 (October 1992)

    Google Scholar 

  16. Ducournau, R., Habib, M.: On some algorithms for multiple inheritance in object-oriented programming. In: Bézivin, J., Hullot, J.-M., Lieberman, H., Cointe, P. (eds.) ECOOP 1987. LNCS, vol. 276, pp. 243–252. Springer, Heidelberg (1987)

    Chapter  Google Scholar 

  17. Duggan, D., Techaubol, C.-C.: Modular mixin-based inheritance for application frameworks. In: Proceedings OOPSLA 2001, pp. 223–240 (October 2001)

    Google Scholar 

  18. Flatt, M., Krishnamurthi, S., Felleisen, M.: Classes and mixins. In: Proceedings of the 25th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, pp. 171–183. ACM Press, New York (1998)

    Chapter  Google Scholar 

  19. Goldberg, A., Robson, D.: Smalltalk 80: the Language and its Implementation. Addison Wesley, Reading (1983)

    MATH  Google Scholar 

  20. Graube, N.: Metaclass compatibility. In: Proceedings OOPSLA 1989, ACM SIGPLAN Notices, vol. 24, pp. 305–316 (October 1989)

    Google Scholar 

  21. Guttag, J.V., Horning, J.J., Wing, J.M.: The larch family of specification languages. IEEE Transactions on Software Engineering 2(5), 24–36 (1985)

    Google Scholar 

  22. Ingalls, D., Kaehler, T., Maloney, J., Wallace, S., Kay, A.: Back to the future: The story of Squeak, A practical Smalltalk written in itself. In: Proceedings OOPSLA 1997, pp. 318–326 (November 1997)

    Google Scholar 

  23. Keene, S.E.: Object-Oriented Programming in Common-Lisp. Addison Wesley, Reading (1989)

    MATH  Google Scholar 

  24. Kniesel, G.: Type-safe delegation for run-time component adaptation. In: Guerraoui, R. (ed.) ECOOP 1999. LNCS, vol. 1628, pp. 351–366. Springer, Heidelberg (1999)

    Chapter  Google Scholar 

  25. LaLonde, W., Pugh, J.: Subclassing ≠ Subtyping ≠ Is-a. Journal of Object-Oriented Programming 3(5), 57–62 (1991)

    Google Scholar 

  26. Madsen, O.L., Magnusson, B., Moller-Pedersen, B.: Strong typing of object-oriented languages revisited. In: Proceedings OOPSLA/ECOOP 1990, ACM SIGPLAN Notices, vol. 25, pp. 140–150 (October 1990)

    Google Scholar 

  27. Mens, T., van Limberghen, M.: Encapsulation and composition as orthogonal operators on mixins: A solution to multiple inheritance problems. Object Oriented Systems 3(1), 1–30 (1996)

    Google Scholar 

  28. Meyer, B.: Eiffel: The Language. Prentice-Hall, Englewood Cliffs (1992)

    MATH  Google Scholar 

  29. Meyer, B.: Object-Oriented Software Construction, 2nd edn. Prentice-Hall, Englewood Cliffs (1997)

    MATH  Google Scholar 

  30. Mezini, M.: Dynamic object evolution without name collisions. In: Aksit, M., Matsuoka, S. (eds.) ECOOP 1997. LNCS, vol. 1241, pp. 190–219. Springer, Heidelberg (1997)

    Chapter  Google Scholar 

  31. Mezini, M., Ostermann, K.: Integrating independent components with ondemand remodularization. In: Proceedings OOPSLA 2002, pp. 52–67 (November 2002)

    Google Scholar 

  32. Moon, D.A.: Object-oriented programming with flavors. In: Proceedings OOPSLA 1986, ACM SIGPLAN Notices, vol. 21, pp. 1–8 (November 1986)

    Google Scholar 

  33. Sakkinen, M.: Disciplined inheritance. In: Cook, S. (ed.) Proceedings ECOOP 1989, Nottingham, pp. 39–56. Cambridge University Press, Cambridge (1989)

    Google Scholar 

  34. Sakkinen, M.: The darker side of C++ revisited. Structured Programming 13(4), 155–177 (1992)

    Google Scholar 

  35. Schaffert, C., Cooper, T., Bullis, B., Killian, M., Wilpolt, C.: An Introduction to Trellis/Owl. In: Proceedings OOPSLA 1986, ACM SIGPLAN Notices, vol. 21, pp. 9–16 (November 1986)

    Google Scholar 

  36. Schärli, N., Black, A.: A browser for incremental programming. Technical Report CSE-03-008, OGI School of Science & Engineering, Beaverton, Oregon, USA (April 2003)

    Google Scholar 

  37. Schärli, N., Nierstrasz, O., Ducasse, S., Wuyts, R., Black, A.: Traits: The formal model. Technical Report IAM-02-006, Institut für Informatik, Universität Bern, Switzerland (November 2002), Also available as Technical Report CSE-02-013, OGI School of Science & Engineering, Beaverton, Oregon, USA

    Google Scholar 

  38. Snyder, A.: Encapsulation and inheritance in object-oriented programming languages. In: Proceedings OOPSLA 1986, ACM SIGPLAN Notices, vol. 21, pp. 38–45 (November 1986)

    Google Scholar 

  39. Snyder, A.: Inheritance and the development of encapsulated software systems. In: Research Directions in Object-Oriented Programming, pp. 165–188. MIT Press, Cambridge (1987)

    Google Scholar 

  40. Steele, G.L.: Common Lisp The Language, 2nd edn. Digital Press (1990) (book)

    Google Scholar 

  41. Stroustrup, B.: The C++ Programming Language. Addison Wesley, Reading (1986)

    MATH  Google Scholar 

  42. Stroustrup, B.: The Design and Evolution of C++. Addison-Wesley, Reading (1994)

    Google Scholar 

  43. Sweeney, P.F., Gil, J. (Yossi): Space and time-efficient memory layout for multiple inheritance. In: Proceedings OOPSLA 1999, pp. 256–275. ACM Press, New York (1999)

    Chapter  Google Scholar 

  44. Taivalsaari, A.: On the notion of inheritance. ACM Computing Surveys 28(3), 438–479 (1996)

    Article  Google Scholar 

  45. Ungar, D., Smith, R.B.: Self: The power of simplicity. In: Proceedings OOPSLA 1987, ACM SIGPLAN Notices, vol. 22, pp. 227–242 (December 1987)

    Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2003 Springer-Verlag Berlin Heidelberg

About this paper

Cite this paper

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. https://doi.org/10.1007/978-3-540-45070-2_12

Download citation

  • DOI: https://doi.org/10.1007/978-3-540-45070-2_12

  • Publisher Name: Springer, Berlin, Heidelberg

  • Print ISBN: 978-3-540-40531-3

  • Online ISBN: 978-3-540-45070-2

  • eBook Packages: Springer Book Archive

Publish with us

Policies and ethics