skip to main content
research-article
Free Access

FeatherTrait: A modest extension of Featherweight Java

Published:14 March 2008Publication History
Skip Abstract Section

Abstract

In the context of statically typed, class-based languages, we investigate classes that can be extended with trait composition. A trait is a collection of methods without state; it can be viewed as an incomplete stateless class. Traits can be composed in any order, but only make sense when imported by a class that provides state variables and additional methods to disambiguate conflicting names arising between the imported traits. We introduce FeatherTrait Java (FTJ), a conservative extension of the simple lightweight class-based calculus Featherweight Java (FJ) with statically typed traits. In FTJ, classes can be built using traits as basic behavioral bricks; method conflicts between imported traits must be resolved explicitly by the user either by (i) aliasing or excluding method names in traits, or by (ii) overriding explicitly the conflicting methods in the class or in the trait itself. We present an operational semantics with a lookup algorithm, and a sound type system that guarantees that evaluating a well-typed expression never yields a message-not-understood run-time error nor gets the interpreter stuck. We give examples of the increased expressive power of the trait-based inheritance model. The resulting calculus appears to be a good starting point for a rigorous mathematical analysis of typed class-based languages featuring trait-based inheritance.

References

  1. Abadi, M. and Cardelli, L. 1996. A Theory of Objects. Springer Verlag, New York. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Allen, E., Chase, D., Luchangco, V., Maessen, J.-W., Ryu, S., Steele, G. L., and Tobin-Hochstadt, S. 2007. The Fortress Language Specification, version 1.0. http://research.sun.com/projects/plrg/fortress.pdf.Google ScholarGoogle Scholar
  3. Allen, E. E., Bannet, J., and Cartwright, R. 2003. Mixins in generic java are sound. Tech. rep., Rice University.Google ScholarGoogle Scholar
  4. Ancona, D., Lagorio, G., and Zucca, E. 2003. Jam - designing a Java extension with mixins. ACM Trans. Prog. Lang. Syst. 25, 5, 641--712. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. Ancona, D. and Zucca, E. 2002a. A calculus of module system. J. Funct. Program 12, 12, 91--132. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. Ancona, D. and Zucca, E. 2002b. A theory of mixin modules: Algebraic laws and reduction semantics. Math. Struct. Comput. Sci. 12, 5, 701--737. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. Bono, V., Bugliesi, M., Dezani-Ciancaglini, M., and Liquori, L. 1997. Subtyping constraint for incomplete objects. In Proceedings of TAPSOFT/CAAP. Lecture Notes in Computer Science, vol. 1214. Springer Verlag, New York, 465--477. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Bono, V., Patel, A., and Shmatikov, V. 1999. A core calculus of classes and mixins. In Proceedings of ECOOP. Lecture Notes in Computer Science, vol. 1628. Springer-Verlag, New York. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Bracha, G. 1992. The Programming Language Jigsaw: Mixins, modularity and multiple inheritance. Ph.D. dissertation, University of Utah. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Bracha, G. and Cook, W. R. 1990. Mixin-based inheritance. In Proceedings of OOPSLA/ECOOP. SIGPLAN Notices, vol. 25(10). ACM, New York, 303--311. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Cardelli, L. 1995. Obliq: A language with distributed scope. Comput. Syst. 8, 1, 27--59.Google ScholarGoogle Scholar
  12. Di Gianantonio, P., Honsell, F., and Liquori, L. 1998. A lambda calculus of objects with self-inflicted extension. In Proceedings of OOPSLA. ACM, New York, 166--178. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. Ducasse, S., Nierstrasz, O., Schärli, N., Wuyts, R., and Black, A. P. 2006. Traits: A mechanism for fine-grained reuse. ACM Trans. Program. Lang. Syst. 28, 2, 331--388. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Duggan, D. and Sourelis, C. 1996. Mixin modules. In Proceedings of ICFP. SIGPLAN Notices, vol. 31(6). ACM, New York, 262--273. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Findler, R. B. and Flatt, M. 1998. Modular object-oriented programming with units and mixins. In Proceedings of ICFP. SIGPLAN Notices. ACM, New York, 94--104. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. Fisher, K. and Reppy, J. 2004. Statically typed traits. http://www.cs.uchicago.edu/files/tr-authentic/TR-2003-13.pdf. (The early version “A Typed Calculus of Traits” has been presented at FOOL 10.)Google ScholarGoogle Scholar
  17. Flatt, M. and Felleisen, M. 1998. Units: Cool modules for HOT languages. In Proceedings of PLDI. SIGPLAN Notices. ACM, New York, 236--248. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. Flatt, M., Krishnamurthi, S., and Felleisen, M. 1998. Classes and mixins. In Proceedings of POPL. ACM, New York, 171--183. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. Goldberg, A. and Robson, D. 1983. Smalltalk-80: the Language and its Implementation. Addison-Wesley, Reading, MA. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. Hirschowitz, T., Leroy, X., and Wells, J. B. 2004. Call-by-value mixin modules: Reduction semantics, side effects, types. In Proceedings of ESOP. Lecture Notes in Computer Science, 2986, Springer-Verlag, New York, 64--78.Google ScholarGoogle Scholar
  21. Igarashi, A., Pierce, B., and Wadler, P. 2001. Featherweight Java: A minimal core calculus for Java and GJ. ACM Trans. Prog. Lang. Syst. 23, 3, 396--450. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. Kiczales, G., Lamping, J., Mendhekar, A., Maeda, C., Lopes, C. V., Loingtier, J.-M., and Irwin, J. 1997. Aspect-oriented programming. In Proceedings of ECOOP. Lecture Notes in Computer Science, 1241, Springer-Verlag, New York, 220--242.Google ScholarGoogle Scholar
  23. Liquori, L. 1997. An extended theory of primitive objects: first order system. In Proceedings of ECOOP. Lecture Notes in Computer Science, 1241, Springer-Verlag, New York, 146--169.Google ScholarGoogle Scholar
  24. Liquori, L. 1998. On object extension. In Proceedings of ECOOP. Lecture Notes in Computer Science, 1445, Springer-Verlag, New York, 498--552. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. Liquori, L. and Spiwack, A. 2004. Featherweight-trait Java : A trait-based extension for FJ. Tech. Rep. RR-5247, INRIA. Juin. http://www.inria.fr/rrrt/rr-5247.html.Google ScholarGoogle Scholar
  26. Liquori, L. and Spiwack, A. 2008. Extending FeatherTrait Java with interfaces. Theoret. Comput. Sci. To appear. Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. Mezini, M. 2002. Towards variational object-oriented programming: The rondo model. Tech. Rep. TUD-ST-2002-02, Software Technology Group, Darmstadt University of Technology.Google ScholarGoogle Scholar
  28. Microsoft. The C# Home Page. http://msdn.microsoft.com/vcsharp/.Google ScholarGoogle Scholar
  29. Milner, R., Tofte, M., Harper, R., and MacQueen, D. 1997. The Definition of Standard ML (Revised). MIT Press, Cambridge, MA. Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. Moby Team. 2007. The Moby home page. http://moby.cs.uchicago.edu/.Google ScholarGoogle Scholar
  31. Nierstrasz, O., Ducasse, S., and Schärli, N. 2006. Flattening traits. J. Obj. Tech. 5, 4, 129--148.Google ScholarGoogle ScholarCross RefCross Ref
  32. Quitslund, P. J. 2004. Java traits -- Improving opportunities for reuse. Tech. Rep. CSE-04-005, OGI School of Science and Engineering. http://www.ogi.edu/csee/tech-reports/2004/04-005.pdf.Google ScholarGoogle Scholar
  33. Scala Team. 2007. The scala home page. http://scala.epfl.ch/.Google ScholarGoogle Scholar
  34. Schärli, N., Ducasse, S., Nierstrasz, O., and Black, A. 2003. Traits: Composable units of behaviour. In Proceedings of ECOOP. Lecture Notes in Computer Science, 2743, Springer-Verlag, New York, 248--274.Google ScholarGoogle Scholar
  35. Smith, C. and Drossopoulou, S. 2005. Chai: Typed traits in Java. In Proceedings of ECOOP. Lecture Notes in Computer Science, 3586, Springer-Verlag, New York, 453--478. Google ScholarGoogle ScholarDigital LibraryDigital Library
  36. Snyder, A. 1987. Inheritance and the development of encapsulated software systems. In Research Directions in Object-Oriented Programming. MIT Press, Cambridge, MA, 165--188. Google ScholarGoogle ScholarDigital LibraryDigital Library
  37. Stroustrup, B. 1997. The C++ Programming Language, Ch. 15, Third Ed. Addison Wesley, Reading, MA. Google ScholarGoogle ScholarDigital LibraryDigital Library
  38. Sun. Java Technology. http://java.sun.com/.Google ScholarGoogle Scholar
  39. Ungar, D. and Smith, R. B. 1987. Self: The power of simplicity. In Proceedings of OOPSLA. ACM, New York, 227--241. Google ScholarGoogle ScholarDigital LibraryDigital Library
  40. Wells, J. B. and Vestergaard, R. 2000. Equational reasoning for linking with first-class primitive modules. In Proceedings of ESOP. Lecture Notes in Computer Science, vol. 1782. Springer Verlag, New York, 412--428. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. FeatherTrait: A modest extension of Featherweight Java

                Recommendations

                Reviews

                Alexandre Bergel

                A trait is an elementary unit of behavior for structuring object-oriented programs. A trait is essentially a set of methods intended to be composed with other traits in order to form a new trait. Moreover, a trait may be used by classes in order to share behavior between dissociated class hierarchies. Traits are traditionally perceived as an alternative to multiple inheritance, and have had a significant practical and theoretical impact. FeatherTrait is a new calculus based on Featherweight Java that captures the essence of traits and proposes a simple type system that type-checks traits usages by classes. As mentioned by the authors, several alternative type systems have been proposed, and the main contribution of FeatherTrait is that it considers verification of traits composition as a noninvasive addition mechanism in the compilation phase. Type-checking traits when they are effectively used by some classes is an additional step inserted before the class type-checking. The great benefit is to leave most of the different phases of the compilation untouched. This represents a plausible scenario for an adoption of traits in a statically typed language such as Java, since no major overhaul has to be considered. The ideas, calculus, and proofs are clearly presented, and the authors make a great effort to motivate different aspects of their type system and consider the related work. This paper will definitely find an audience among people interested in traits and class inheritance in general. Online Computing Reviews Service

                Access critical reviews of Computing literature here

                Become a reviewer for Computing Reviews.

                Comments

                Login options

                Check if you have access through your login credentials or your institution to get full access on this article.

                Sign in

                Full Access

                • Published in

                  cover image ACM Transactions on Programming Languages and Systems
                  ACM Transactions on Programming Languages and Systems  Volume 30, Issue 2
                  March 2008
                  217 pages
                  ISSN:0164-0925
                  EISSN:1558-4593
                  DOI:10.1145/1330017
                  Issue’s Table of Contents

                  Copyright © 2008 ACM

                  Publisher

                  Association for Computing Machinery

                  New York, NY, United States

                  Publication History

                  • Published: 14 March 2008
                  • Accepted: 1 February 2007
                  • Revised: 1 June 2006
                  • Received: 1 May 2005
                  Published in toplas Volume 30, Issue 2

                  Permissions

                  Request permissions about this article.

                  Request Permissions

                  Check for updates

                  Qualifiers

                  • research-article
                  • Research
                  • Refereed

                PDF Format

                View or Download as a PDF file.

                PDF

                eReader

                View online with eReader.

                eReader
                About Cookies On This Site

                We use cookies to ensure that we give you the best experience on our website.

                Learn more

                Got it!