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.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Preview
Unable to display preview. Download preview PDF.
References
Achermann, F., Nierstrasz, O.: Explicit Namespaces. In: Weck, W., Gutknecht, J. (eds.) JMLC 2000. LNCS, vol. 1897, pp. 77–89. Springer, Heidelberg (2000)
America, P.: Designing an object-oriented programming language with behavioural subtyping. In: Proceedings REX/FOOLS Workshop, Noordwijkerhout (June 1990)
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)
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)
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)
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
Borning, A.H., Ingalls, D.H.H.: Multiple inheritance in Smalltalk-80. In: Proceedings at the National Conference on AI, Pittsburgh, PA (1982)
Bouraqadi-Saadani, N.M.N., Ledoux, T., Rivard, F.: Safe metaclass programming. In: Proceedings OOPSLA 1998, pp. 84–96 (1998)
Bracha, G.: The Programming Language Jigsaw: Mixins, Modularity and Multiple Inheritance. Ph.D. thesis, Dept. of Computer Science, University of Utah (March 1992)
Bracha, G., Cook, W.: Mixin-based inheritance. In: Proceedings OOPSLA/ ECOOP 1990, ACM SIGPLAN Notices, October 1990, vol. 25, pp. 303–311 (1990)
Cook, S.: OOPSLA 1987 Panel P2: Varieties of inheritance. In: OOPSLA 1987 Addendum To The Proceedings, pp. 35–40. ACM Press, New York (1987)
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)
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)
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)
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)
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)
Duggan, D., Techaubol, C.-C.: Modular mixin-based inheritance for application frameworks. In: Proceedings OOPSLA 2001, pp. 223–240 (October 2001)
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)
Goldberg, A., Robson, D.: Smalltalk 80: the Language and its Implementation. Addison Wesley, Reading (1983)
Graube, N.: Metaclass compatibility. In: Proceedings OOPSLA 1989, ACM SIGPLAN Notices, vol. 24, pp. 305–316 (October 1989)
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)
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)
Keene, S.E.: Object-Oriented Programming in Common-Lisp. Addison Wesley, Reading (1989)
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)
LaLonde, W., Pugh, J.: Subclassing ≠ Subtyping ≠ Is-a. Journal of Object-Oriented Programming 3(5), 57–62 (1991)
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)
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)
Meyer, B.: Eiffel: The Language. Prentice-Hall, Englewood Cliffs (1992)
Meyer, B.: Object-Oriented Software Construction, 2nd edn. Prentice-Hall, Englewood Cliffs (1997)
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)
Mezini, M., Ostermann, K.: Integrating independent components with ondemand remodularization. In: Proceedings OOPSLA 2002, pp. 52–67 (November 2002)
Moon, D.A.: Object-oriented programming with flavors. In: Proceedings OOPSLA 1986, ACM SIGPLAN Notices, vol. 21, pp. 1–8 (November 1986)
Sakkinen, M.: Disciplined inheritance. In: Cook, S. (ed.) Proceedings ECOOP 1989, Nottingham, pp. 39–56. Cambridge University Press, Cambridge (1989)
Sakkinen, M.: The darker side of C++ revisited. Structured Programming 13(4), 155–177 (1992)
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)
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)
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
Snyder, A.: Encapsulation and inheritance in object-oriented programming languages. In: Proceedings OOPSLA 1986, ACM SIGPLAN Notices, vol. 21, pp. 38–45 (November 1986)
Snyder, A.: Inheritance and the development of encapsulated software systems. In: Research Directions in Object-Oriented Programming, pp. 165–188. MIT Press, Cambridge (1987)
Steele, G.L.: Common Lisp The Language, 2nd edn. Digital Press (1990) (book)
Stroustrup, B.: The C++ Programming Language. Addison Wesley, Reading (1986)
Stroustrup, B.: The Design and Evolution of C++. Addison-Wesley, Reading (1994)
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)
Taivalsaari, A.: On the notion of inheritance. ACM Computing Surveys 28(3), 438–479 (1996)
Ungar, D., Smith, R.B.: Self: The power of simplicity. In: Proceedings OOPSLA 1987, ACM SIGPLAN Notices, vol. 22, pp. 227–242 (December 1987)
Author information
Authors and Affiliations
Editor information
Editors and Affiliations
Rights 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