Skip to main content

Stateful Traits

  • Conference paper

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

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.

Keywords

  • Instance Variable
  • Stateful Trait
  • Trait Composition
  • Multiple Inheritance
  • Client Class

These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.

This is a preview of subscription content, access via your institution.

Buying options

Chapter
USD   29.95
Price excludes VAT (USA)
  • DOI: 10.1007/978-3-540-71836-9_4
  • Chapter length: 25 pages
  • Instant PDF download
  • Readable on all devices
  • Own it forever
  • Exclusive offer for individuals only
  • Tax calculation will be finalised during checkout
eBook
USD   59.99
Price excludes VAT (USA)
  • ISBN: 978-3-540-71836-9
  • Instant PDF download
  • Readable on all devices
  • Own it forever
  • Exclusive offer for individuals only
  • Tax calculation will be finalised during checkout
Softcover Book
USD   79.99
Price excludes VAT (USA)

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)

    CrossRef  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)

    CrossRef  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)

    CrossRef  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)

    CrossRef  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)

    CrossRef  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)

    CrossRef  Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Editor information

Editors and Affiliations

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)