Chai: Traits for Java-Like Languages

  • Charles Smith
  • Sophia Drossopoulou
Part of the Lecture Notes in Computer Science book series (LNCS, volume 3586)


Traits support the factoring out of common behaviour, and its integration into classes in a manner that coexists smoothly with inheritance-based structuring mechanisms.

We designed the language Chai, which incorporates statically typed traits into a simple Java-inspired base language, and we discuss three versions of the language: Chai1, where traits are only a mechanism for the creation of classes; Chai2 where traits are a mechanism for the creation of classes, and can also introduce types, and Chai3 where traits play a role at runtime, and can can be applied to objects, and change the objects’ behaviour. We give formal models for these languages, outline the proof of soundness, and our prototype implementation.


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.


  1. 1.
    Agesen, O., Bak, L., Chambers, C., Chang, B.-W., Hölzle, U., Maloney, J., Smith, R.B., Ungar, D.: The Self 4.0 Programmer’s Reference Manual. Sun Microsystems, Inc (1995)Google Scholar
  2. 2.
    Ancona, D., Lagorio, G., Zucca, E.: Jam - A Smooth Extension of Java with Mixins. In: Bertino, E. (ed.) ECOOP 2000. LNCS, vol. 1850, pp. 154–178. Springer, Heidelberg (2000)CrossRefGoogle Scholar
  3. 3.
    Black, A., Schärli, N., Ducasse, S.: Applying Traits to the Smalltalk Collection Hierarchy. In: ACM Conference on Object Oriented Systems, Languages and Applications (OOPSLA), October 2003, pp. 47–64 (2003)Google Scholar
  4. 4.
    Bracha, G.: The programming language jigsaw: mixins, modularity and multiple inheritance. PhD thesis, University of Utah (1992)Google Scholar
  5. 5.
    Bracha, G., Cook, W.: Mixin-Based Inheritance. In: Meyrowitz, N. (ed.) Proceedings of the Conference on Object-Oriented Programming: Systems, Languages, and Applications / Proceedings of the European Conference on Object-Oriented Programming, Ottawa, Canada, pp. 303–311. ACM Press, New York (1990)CrossRefGoogle Scholar
  6. 6.
    Bracha, G., Odersky, M., Stoutamire, D., Wadler, P.: Making the Future Safe for the Past: Adding Genericity to the Java Programming Language. In: Chambers, C. (ed.) ACM Symposium on Object Oriented Programming: Systems, Languages, and Applications (OOPSLA), Vancouver, BC, pp. 183–200 (1998)Google Scholar
  7. 7.
    Drossopoulou, S., Damiani, F., Dezani-Ciancaglini, M., Giannini, P.: Fickle: Dynamic object re-classification. In: Knudsen, J.L. (ed.) ECOOP 2001. LNCS, vol. 2072, pp. 130–149. Springer, Heidelberg (2001)CrossRefGoogle Scholar
  8. 8.
    Ducasse, S., Nierstrasz, O., Schärli, N., Wuyts, R.: Traits - Composable Units of Behaviour. University of Berne, Software Composition Group,
  9. 9.
    Ernst, E.: Family Polymorphism. In: Knudsen, J.L. (ed.) ECOOP 2001. LNCS, vol. 2072, pp. 303–326. Springer, Heidelberg (2001)CrossRefGoogle Scholar
  10. 10.
    Fisher, K., Reppy, J.: Statically Typed Traits. Technical Report TR-2003-13, Department of Computer Science, University of Chicago, December 2003. presented at FOOL (January 2004)Google Scholar
  11. 11.
    Flatt, M., Krishnamurthi, S., Felleisen, M.: Classes and Mixins. In: Conference Record of POPL 1998: The 25th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, San Diego, California, New York, pp. 171–183 (1998)Google Scholar
  12. 12.
    Igarashi, A., Pierce, B., Wadler, P.: Featherweight Java: A minimal core calculus for Java and GJ. In: Meissner, L. (ed.) Proceedings of the 1999 ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages & Applications (OOPSLA 1999), N.Y, vol. 34(10), pp. 132–146 (1999)Google Scholar
  13. 13.
    Liquori, L., Spiwack, A.: Featherweight-Trait Java, A Trait-based Extension for FJ (2004),
  14. 14.
    Meyer, B.: Eiffel: the Language. Prentice-Hall, Englewood Cliffs (1988)Google Scholar
  15. 15.
    Odersky, M., Altherr, P., Cremet, V., Emir, B., Micheloud, S., Mihaylov, N., Schinz, M., Stenman, E., Zenge, M.: The Scala Language Specification Version 1.0. Technical report, Programming Methods Laboratory, EPFL, Switzerland (2004)Google Scholar
  16. 16.
    Odersky, M., Cremet, V., Röckl, C., Zenger, M.: A Nominal Theory of Objects with Dependent Types. In: Cardelli, L. (ed.) ECOOP 2003. LNCS, vol. 2743. Springer, Heidelberg (2003)CrossRefGoogle Scholar
  17. 17.
    Quitslund, P.J., Black, A.P.: Java with Traits — Improving Opportunities for Reuse. In: Malenfant, J., Østvold, B.M. (eds.) ECOOP 2004. LNCS, vol. 3344. Springer, Heidelberg (2005)Google Scholar
  18. 18.
    Schärli, N., Ducasse, S., Nierstrasz, O., Black, A.: Traits: Composable Units of Behavior. In: Cardelli, L. (ed.) ECOOP 2003. LNCS, vol. 2743. Springer, Heidelberg (2003)CrossRefGoogle Scholar
  19. 19.
    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)Google Scholar
  20. 20.
    Smith, C.: Typed Traits, September. MSc thesis - Department of Computing. Imperial College, London (September 2004),
  21. 21.
    Stroustrup, B.: Multiple inheritance for C++. In: Proceedings of the Spring 1987 European Unix Users Group Conference, Helsinki (1987)Google Scholar
  22. 22.
    Ungar, D., Smith, R.B.: Self: The power of simplicity. In: Conference proceedings on Object-oriented programming systems, languages and applications, pp. 227–242. ACM Press, New York (1987)CrossRefGoogle Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2005

Authors and Affiliations

  • Charles Smith
    • 1
  • Sophia Drossopoulou
    • 1
  1. 1.Department of ComputingImperial College London 

Personalised recommendations