Skip to main content

Stateful Traits

  • Conference paper
Book cover Advances in Smalltalk (ISC 2006)

Part of the book series: Lecture Notes in Computer Science ((LNPSE,volume 4406))

Included in the following conference series:

Abstract

Traits offer a fine-grained mechanism to compose classes from reusable components while avoiding problems of fragility brought by multiple inheritance and mixins. Traits as originally proposed are stateless, that is, they contain only methods, but no instance variables. State can only be accessed within traits by accessors, which become required methods of the trait. Although this approach works reasonably well in practice, it means that many traits, viewed as software components, are artificially incomplete, and classes that use such traits may contain significant amounts of boilerplate glue code. Although these limitations are largely mitigated by proper tool support, we seek a cleaner solution that supports stateful traits. The key difficulty is how to handle conflicts that arise when composed traits contribute instance variables whose names clash. We present a solution that is faithful to the guiding principle of stateless traits: the client retains control of the composition. Stateful traits consist of a minimal extension to stateless traits in which instance variables are purely local to the scope of a trait, unless they are explicitly made accessible by the composing client of a trait. Naming conflicts are avoided, and variables of disjoint traits can be explicitly merged by clients. We discuss and compare two implementation strategies, and briefly present a case study in which stateful traits have been used to refactor the trait-based version of the Smalltalk collection hierarchy.

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 39.99
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 54.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. Bracha, G., Cook, W.: Mixin-based inheritance. In: Proceedings OOPSLA/ECOOP ’90. ACM SIGPLAN Notices, vol. 25, pp. 303–311 (Oct. 1990)

    Google Scholar 

  2. Bak, L., et al.: Mixins in Strongtalk. In: ECOOP ’02 Workshop on Inheritance (June 2002)

    Google Scholar 

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

    Google Scholar 

  4. Black, A.P., Schärli, N., Ducasse, S.: Applying traits to the Smalltalk collection hierarchy. In: Proceedings OOPSLA’03 (International Conference on Object-Oriented Programming Systems, Languages and Applications), vol. 38, October 2003, pp. 47–64 (2003)

    Google Scholar 

  5. Cardelli, L., et al.: Modula-3 language definition. ACM SIGPLAN Notices 27(8), 15–42 (1992)

    Article  Google Scholar 

  6. Chambers, C.: Object-oriented multi-methods in cecil. In: Lehrmann Madsen, O. (ed.) ECOOP 1992. LNCS, vol. 615, pp. 33–56. Springer, Heidelberg (1992)

    Chapter  Google Scholar 

  7. Ducasse, S., et al.: Traits: A mechanism for fine-grained reuse. ACM Transactions on Programming Languages and Systems 28(2), 331–388 (2006)

    Article  Google Scholar 

  8. The fortress language specification, http://research.sun.com/projects/plrg/fortress0866.pdf

  9. Fisher, K., Reppy, J.: Statically typed traits. Technical Report TR-2003-13, University of Chicago, Department of Computer Science (December 2003)

    Google Scholar 

  10. Ingalls, D., et al.: Back to the future: The story of Squeak, A practical Smalltalk written in itself. In: Proceedings OOPSLA ’97, November 1997. ACM SIGPLAN Notices, pp. 318–326. ACM Press, New York (1997)

    Chapter  Google Scholar 

  11. The jikes research virtual machine, http://jikesrvm.sourceforge.net/

  12. Krogdahl, S.: Multiple inheritance in simula-like languages. In: BIT 25, pp. 318–326 (1985)

    Google Scholar 

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

    MATH  Google Scholar 

  14. Mohnen, M.: Interfaces with default implementations in Java. In: Conference on the Principles and Practice of Programming in Java, Dublin, Ireland, June 2002, pp. 35–40. ACM Press, New York (2002)

    Google Scholar 

  15. Nierstrasz, O., Ducasse, S., Schärli, N.: Flattening Traits. Journal of Object Technology 5(4), 129–148 (2006)

    Google Scholar 

  16. Python, http://www.python.org

  17. Scala home page, http://lamp.epfl.ch/scala/

  18. Smith, C., Drossopoulou, S.: Chai: Typed traits in Java. In: Black, A.P. (ed.) ECOOP 2005. LNCS, vol. 3586, Springer, Heidelberg (2005)

    Google Scholar 

  19. Schärli, N., et al.: Traits: Composable units of behavior. In: Cardelli, L. (ed.) ECOOP 2003. LNCS, vol. 2743, pp. 248–274. Springer, Heidelberg (2003)

    Google Scholar 

  20. Stroustrup, B., Ellis, M.A.: The Annotated C++ Reference Manual. Addison-Wesley, Reading (1990)

    Google Scholar 

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

    Chapter  Google Scholar 

  22. Slate, http://slate.tunes.org

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

    Google Scholar 

  24. Ungar, D., et al.: Organizing programs without classes. LISP and SYMBOLIC COMPUTATION: An international journal 4(3) (1991)

    Google Scholar 

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

    Chapter  Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Editor information

Wolfgang De Meuter

Rights and permissions

Reprints and permissions

Copyright information

© 2007 Springer Berlin Heidelberg

About this paper

Cite this paper

Bergel, A., Ducasse, S., Nierstrasz, O., Wuyts, R. (2007). Stateful Traits. In: De Meuter, W. (eds) Advances in Smalltalk. ISC 2006. Lecture Notes in Computer Science, vol 4406. Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-540-71836-9_4

Download citation

  • DOI: https://doi.org/10.1007/978-3-540-71836-9_4

  • Publisher Name: Springer, Berlin, Heidelberg

  • Print ISBN: 978-3-540-71835-2

  • Online ISBN: 978-3-540-71836-9

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics