skip to main content
research-article
Open access

FeatherTrait: A modest extension of Featherweight Java

Published: 14 March 2008 Publication History

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.
[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.
[3]
Allen, E. E., Bannet, J., and Cartwright, R. 2003. Mixins in generic java are sound. Tech. rep., Rice University.
[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.
[5]
Ancona, D. and Zucca, E. 2002a. A calculus of module system. J. Funct. Program 12, 12, 91--132.
[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.
[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.
[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.
[9]
Bracha, G. 1992. The Programming Language Jigsaw: Mixins, modularity and multiple inheritance. Ph.D. dissertation, University of Utah.
[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.
[11]
Cardelli, L. 1995. Obliq: A language with distributed scope. Comput. Syst. 8, 1, 27--59.
[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.
[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.
[14]
Duggan, D. and Sourelis, C. 1996. Mixin modules. In Proceedings of ICFP. SIGPLAN Notices, vol. 31(6). ACM, New York, 262--273.
[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.
[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.)
[17]
Flatt, M. and Felleisen, M. 1998. Units: Cool modules for HOT languages. In Proceedings of PLDI. SIGPLAN Notices. ACM, New York, 236--248.
[18]
Flatt, M., Krishnamurthi, S., and Felleisen, M. 1998. Classes and mixins. In Proceedings of POPL. ACM, New York, 171--183.
[19]
Goldberg, A. and Robson, D. 1983. Smalltalk-80: the Language and its Implementation. Addison-Wesley, Reading, MA.
[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.
[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.
[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.
[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.
[24]
Liquori, L. 1998. On object extension. In Proceedings of ECOOP. Lecture Notes in Computer Science, 1445, Springer-Verlag, New York, 498--552.
[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.
[26]
Liquori, L. and Spiwack, A. 2008. Extending FeatherTrait Java with interfaces. Theoret. Comput. Sci. To appear.
[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.
[28]
Microsoft. The C# Home Page. http://msdn.microsoft.com/vcsharp/.
[29]
Milner, R., Tofte, M., Harper, R., and MacQueen, D. 1997. The Definition of Standard ML (Revised). MIT Press, Cambridge, MA.
[30]
Moby Team. 2007. The Moby home page. http://moby.cs.uchicago.edu/.
[31]
Nierstrasz, O., Ducasse, S., and Schärli, N. 2006. Flattening traits. J. Obj. Tech. 5, 4, 129--148.
[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.
[33]
Scala Team. 2007. The scala home page. http://scala.epfl.ch/.
[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.
[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.
[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.
[37]
Stroustrup, B. 1997. The C++ Programming Language, Ch. 15, Third Ed. Addison Wesley, Reading, MA.
[38]
Sun. Java Technology. http://java.sun.com/.
[39]
Ungar, D. and Smith, R. B. 1987. Self: The power of simplicity. In Proceedings of OOPSLA. ACM, New York, 227--241.
[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.

Cited By

View all
  • (2023)Variability modulesJournal of Systems and Software10.1016/j.jss.2022.111510195:COnline publication date: 1-Jan-2023
  • (2022)Traits: Correctness-by-Construction for FreeFormal Techniques for Distributed Objects, Components, and Systems10.1007/978-3-031-08679-3_9(131-150)Online publication date: 13-Jun-2022
  • (2020)Featherweight Swift: a Core calculus for Swift’s type systemProceedings of the 13th ACM SIGPLAN International Conference on Software Language Engineering10.1145/3426425.3426939(140-154)Online publication date: 16-Nov-2020
  • Show More Cited By

Recommendations

Comments

Information & Contributors

Information

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
Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

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

Permissions

Request permissions for this article.

Check for updates

Author Tags

  1. Java
  2. inheritance
  3. language design
  4. language semantics

Qualifiers

  • Research-article
  • Research
  • Refereed

Funding Sources

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)83
  • Downloads (Last 6 weeks)17
Reflects downloads up to 02 Mar 2025

Other Metrics

Citations

Cited By

View all
  • (2023)Variability modulesJournal of Systems and Software10.1016/j.jss.2022.111510195:COnline publication date: 1-Jan-2023
  • (2022)Traits: Correctness-by-Construction for FreeFormal Techniques for Distributed Objects, Components, and Systems10.1007/978-3-031-08679-3_9(131-150)Online publication date: 13-Jun-2022
  • (2020)Featherweight Swift: a Core calculus for Swift’s type systemProceedings of the 13th ACM SIGPLAN International Conference on Software Language Engineering10.1145/3426425.3426939(140-154)Online publication date: 16-Nov-2020
  • (2020)Software language engineers’ worst nightmareProceedings of the 13th ACM SIGPLAN International Conference on Software Language Engineering10.1145/3426425.3426933(72-85)Online publication date: 16-Nov-2020
  • (2019)Iteratively Composing Statically Verified TraitsElectronic Proceedings in Theoretical Computer Science10.4204/EPTCS.299.7299(49-55)Online publication date: 20-Aug-2019
  • (2019)A type system for first-class layers with inheritance, subtyping, and swappingScience of Computer Programming10.1016/j.scico.2019.03.008Online publication date: Apr-2019
  • (2017)XtraitjJournal of Systems and Software10.1016/j.jss.2016.07.035131:C(419-441)Online publication date: 1-Sep-2017
  • (2017)Promoting traits into model-driven developmentSoftware and Systems Modeling (SoSyM)10.1007/s10270-015-0505-x16:4(997-1017)Online publication date: 1-Oct-2017
  • (2017)A Unified and Formal Programming Model for Deltas and TraitsProceedings of the 20th International Conference on Fundamental Approaches to Software Engineering - Volume 1020210.1007/978-3-662-54494-5_25(424-441)Online publication date: 22-Apr-2017
  • (2016)Classless JavaACM SIGPLAN Notices10.1145/3093335.299323852:3(14-24)Online publication date: 20-Oct-2016
  • Show More Cited By

View Options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Login options

Full Access

Figures

Tables

Media

Share

Share

Share this Publication link

Share on social media