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.
Chapter PDF
Similar content being viewed by others
References
The Fortress language specification. http://research.sun.com/projects/plrg/fortress.pdf.
The Agile Alliance. Manifesto for Agile Software Development. http://agilemanifesto.org/.
D. Ancona, G. Lagorio, and E. Zucca. Jam—designing a Java extension with mixins. ACM TOPLAS, 25(5):641–712, September 2003.
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.
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.
G. Bracha. The Programming Language JIGSAW: Mixins, Modularity and Multiple Inheritance. PhD thesis, Department of Comp. Sci., Univ. of Utah, 1992.
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.
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.
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.
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.
K. Fisher and J. Reppy. Inheritance-based subtyping. Information and Computation, 177(1):28–55, 2002.
K. Fisher and J. Reppy. A typed calculus of traits. In Electronic proceedings of FOOL 2004, 2004.
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.
E. Gamma, R. Helm, R. Johnson, and J. Vlissides. Design Patterns: Elements of Reusable Object-Oriented Software. Addison-Wesley, 1995.
A. Igarashi, B. Pierce, and P. Wadler. Featherweight Java: A minimal core calculus for Java and GJ. ACM TOPLAS, 23(3):396–450, 2001.
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.
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.
L. Liquori and A Spiwack. Feathertrait: A modest extension of featherweight java. ACM TOPLAS. To appear.
D. Maleyery and J. Aldrich. Combining structural subtyping and external dispatch. In Electronic proceedings of FOOL/WOOD 2007, 2007.
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.
O. Nierstrasz, S. Ducasse, and N. Schärli. Flattening traits. JOT (www.jot.fm), 5(4):129–148, 2006.
M. Odersky. The Scala Language Specification, version 2.4. Technical report, Programming Methods Laboratory, EPFL, Switzerland, 2007.
J. Reppy and A. Turon. A foundation for trait-based metaprogramming. In Electronic proceedings of FOOL/WOOD 2006, 2006.
J. Reppy and A. Turon. Metaprogramming with traits. In ECOOP 2007, volume 4609 of LNCS, pages 373–398. Springer, 2007.
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.
C. Smith and S. Drossopoulou. Chai: Traits for java-like languages. In ECOOP’05, LNCS 3586, pages 453–478. Springer, 2005.
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.
Author information
Authors and Affiliations
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2008 IFIP International Federation for Information Processing
About this paper
Cite this paper
Bono, V., Damiani, F., Giachino, E. (2008). On Traits and Types in a Java-like Setting. In: Ausiello, G., Karhumäki, J., Mauri, G., Ong, L. (eds) Fifth Ifip International Conference On Theoretical Computer Science – Tcs 2008. IFIP International Federation for Information Processing, vol 273. Springer, Boston, MA. https://doi.org/10.1007/978-0-387-09680-3_25
Download citation
DOI: https://doi.org/10.1007/978-0-387-09680-3_25
Publisher Name: Springer, Boston, MA
Print ISBN: 978-0-387-09679-7
Online ISBN: 978-0-387-09680-3
eBook Packages: Computer ScienceComputer Science (R0)