On Traits and Types in a Java-like Setting

  • Viviana Bono
  • Ferruccio Damiani
  • Elena Giachino
Part of the IFIP International Federation for Information Processing book series (IFIPAICT, volume 273)

Abstract

Both single and multiple class-based inheritance are often inappropriate as a reuse mechanism, because classes play two competing roles. Namely, a class is both a generator of instances and a unit of reuse. Traits are composable pure units of behavior reuse, consisting only of methods, that have been proposed as an add-on to single class-based inheritance in order to improve reuse. However, adopting traits as an add-on to traditional class-based inheritance is not enough: classes, besides their primary role of generators of instances, still play the competing role of units of reuse. Therefore, a style of programming oriented to reuse is not enforced by the language, but left to the programmer’s skills. Traits have been originally proposed in the setting of dynamically typed language. When static typing is also taken into account, the role of unit of reuse and the role of type are competing, too.

We argue that, in order to support the development of reusable program components, object oriented programming languages should be designed according to the principle that each software structuring construct must have exactly one role. We propose a realignment of the class-based object-oriented paradigm by presenting programming language features that separate completely the declarations of object type, behavior and generator. We illustrate our proposal through a core calculus and prove the soundness of the type system w.r.t. the operational semantics.

Keywords

Type System Inheritance Composition Flattening 

References

  1. 1.
    The Fortress language specification. http://research.sun.com/projects/plrg/fortress.pdf.Google Scholar
  2. 2.
    The Agile Alliance. Manifesto for Agile Software Development. http://agilemanifesto.org/.Google Scholar
  3. 3.
    D. Ancona, G. Lagorio, and E. Zucca. Jam—designing a Java extension with mixins. ACM TOPLAS, 25(5):641–712, September 2003.Google Scholar
  4. 4.
    A. Bergel, S. Ducasse, O. Nierstrasz, and R. Wuyts. Stateful traits. In Advances in Smalltalk — Proceedings of 14th International Smalltalk Conference (ISC 2006), volume 4406 of LNCS, pages 66–90. Springer, 2007.Google Scholar
  5. 5.
    V. Bono, F. Damiani, and E. Giachino. Separating Type, behavior, and State to Achieve Very Fine-grained Reuse. In Electronic proceedings of FTfJP’07 (http://www.cs.ru.nl/ftfjp/), 2007.Google Scholar
  6. 6.
    G. Bracha. The Programming Language JIGSAW: Mixins, Modularity and Multiple Inheritance. PhD thesis, Department of Comp. Sci., Univ. of Utah, 1992.Google Scholar
  7. 7.
    G. Bracha and W. Cook. Mixin-based inheritance. In ACM Symp. on Object-Oriented Programming: Systems, Languages and Applications 1990, volume 25(10) of SIGPLAN Notices, pages 303–311. ACM Press, October 1990.Google Scholar
  8. 8.
    D. Cassou, S. Ducasse, and R. Wuyts. Redesigning with traits: the nile stream trait-based library. In Proc. International Conference on Dynamic Languages, pages 50–79, 2007.Google Scholar
  9. 9.
    W.R. Cook, W.L. Hill, and P.S. Canning. Inheritance is not subtyping. In ACM Symp. on Principles of Programming Languages 1990, pages 125–135. ACM Press, 1990.Google Scholar
  10. 10.
    S. Ducasse, O. Nierstrasz, N. Schärli, R. Wuyts, and A. Black. Traits: A mechanism for fine-grained reuse. ACM TOPLAS, 28(2):331–388, 2006.CrossRefGoogle Scholar
  11. 11.
    K. Fisher and J. Reppy. Inheritance-based subtyping. Information and Computation, 177(1):28–55, 2002.MathSciNetCrossRefMATHGoogle Scholar
  12. 12.
    K. Fisher and J. Reppy. A typed calculus of traits. In Electronic proceedings of FOOL 2004, 2004.Google Scholar
  13. 13.
    M. Flatt, S. Krishnamurthi, and M. Felleisen. Classes and mixins. In ACM Symp. on Principles of Programming Languages 1998, pages 171–183. ACM Press, 1998.Google Scholar
  14. 14.
    E. Gamma, R. Helm, R. Johnson, and J. Vlissides. Design Patterns: Elements of Reusable Object-Oriented Software. Addison-Wesley, 1995.Google Scholar
  15. 15.
    A. Igarashi, B. Pierce, and P. Wadler. Featherweight Java: A minimal core calculus for Java and GJ. ACM TOPLAS, 23(3):396–450, 2001.CrossRefGoogle Scholar
  16. 16.
    A. Lienhard, S. Ducasse, and G. Arévalo. Identifying traits with formal concept analysis. In Proc. 20th Conference on Automated Software Engineering (ASE’05), pages 66–75. IEEE Computer Society, 2005.Google Scholar
  17. 17.
    M. Van Limberghen and T. Mens. Encapsulation and composition as orthogonal operators on mixins: A solution to multiple inheritance problems. Object Oriented Systems, 3(1):1–30, 1996.Google Scholar
  18. 18.
    L. Liquori and A Spiwack. Feathertrait: A modest extension of featherweight java. ACM TOPLAS. To appear.Google Scholar
  19. 19.
    D. Maleyery and J. Aldrich. Combining structural subtyping and external dispatch. In Electronic proceedings of FOOL/WOOD 2007, 2007.Google Scholar
  20. 20.
    L. Mikhajlov and E. Sekerinski. A Study of the Fragile Base Class Problem. In Proc. ECOOP ’98, volume 1445 of LNCS, pages 355–382. Springer-Verlag, 1998.Google Scholar
  21. 21.
    O. Nierstrasz, S. Ducasse, and N. Schärli. Flattening traits. JOT (www.jot.fm), 5(4):129–148, 2006.Google Scholar
  22. 22.
    M. Odersky. The Scala Language Specification, version 2.4. Technical report, Programming Methods Laboratory, EPFL, Switzerland, 2007.Google Scholar
  23. 23.
    J. Reppy and A. Turon. A foundation for trait-based metaprogramming. In Electronic proceedings of FOOL/WOOD 2006, 2006.Google Scholar
  24. 24.
    J. Reppy and A. Turon. Metaprogramming with traits. In ECOOP 2007, volume 4609 of LNCS, pages 373–398. Springer, 2007.Google Scholar
  25. 25.
    N. Schärli, S. Ducasse, O. Nierstrasz, and A. Black. Traits: Composable units of behavior. In ECOOP 2003, volume 2743 of LNCS, pages 248–274. Springer, 2003.Google Scholar
  26. 26.
    C. Smith and S. Drossopoulou. Chai: Traits for java-like languages. In ECOOP’05, LNCS 3586, pages 453–478. Springer, 2005.Google Scholar
  27. 27.
    A. Snyder. Encapsulation and inheritance in object-oriented programming languages. In ACM Symp. on Object-Oriented Programming: Systems, Languages and Applications 1986, volume 21(11) of SIGPLAN Notices, pages 38–45. ACM Press, 1986.Google Scholar

Copyright information

© IFIP International Federation for Information Processing 2008

Authors and Affiliations

  • Viviana Bono
    • 1
  • Ferruccio Damiani
    • 1
  • Elena Giachino
    • 1
  1. 1.Dipartimento di InformaticaUniversità di TorinoTorinoItaly

Personalised recommendations