Abstract
A trait is a unit of behaviour that can be composed with other traits and used by classes. Traits offer an alternative to multiple inheritance. Conflict resolution of traits, while flexible, does not completely handle accidental method name conflicts: if a trait with method m is composed with another trait defining a different method m then resolving the conflict may prove delicate or infeasible in cases where both versions of m are still needed. In this paper we present freezeable traits, which provide an expressive composition mechanism to support unanticipated method composition conflicts. Our solution introduces private trait methods and lets the class composer change method visibility at composition time (from public to private and vice versa). Moreover two class composers may use different composition policies for the same trait, something which is not possible in mainstream languages. This approach respects the two main design principles of traits: the class composer is empowered and traits can be flattened away. We present an implementation of freezable traits in Smalltalk. As a side-effect of this implementation we introduced private (early-bound and invisible) methods to Smalltalk by distinguishing object-sends from self-sends. Our implementation uses compile-time bytecode manipulation and, as such, introduces no run-time penalties.
- Alexandre Bergel, Stéphane Ducasse, Oscar Nierstrasz, and Roel Wuyts. Stateful traits and their formalization. Journal of Computer Languages, Systems and Structures, 2007. To appear. Google Scholar
Digital Library
- Gilad Bracha and Gary Lindstrom. Modularity meets inheritance. Uucs-91-017, University of Utah, Dept. Comp. Sci., October 1991.Google Scholar
- Gilad Bracha. The Programming Language Jigsaw: Mixins, Modularity and Multiple Inheritance. PhD thesis, Dept. of Computer Science, University of Utah, March 1992. Google Scholar
Digital Library
- Andrew P. Black, Nathanael Schärli, and Stéphane Ducasse. Applying traits to the Smalltalk collection hierarchy. In Proceedings of 17th International Conference on Object-Oriented Programming Systems, Languages and Applications (OOPSLA'03), volume 38, pages 47--64, October 2003. Google Scholar
Digital Library
- Frank W. Calliss. A comparison of module constructs in programming languages. SIGPLAN Not., 26(1):38--46, 1991. Google Scholar
Digital Library
- Marcus Denker, Stéphane Ducasse, and Eric Tanter. Runtime bytecode transformation for Smalltalk. Journal of Computer Languages, Systems and Structures, 32(2--3):125--139, July 2006. Google Scholar
Digital Library
- Stéphane Ducasse, Oscar Nierstrasz, Nathanael Schärli, Roel Wuyts, and Andrew Black. Traits: A mechanism for fine--grained reuse. ACM Transactions on Programming Languages and Systems (TOPLAS), 28(2):331--388, March 2006. Google Scholar
Digital Library
- Matthias Felleisen and Robert Hieb. The revised report on the syntactic theories of sequential control and state. Theor. Comput. Sci., 103(2):235--271, 1992. Google Scholar
Digital Library
- Matthew Flatt, Shriram Krishnamurthi, and Matthias Felleisen. Classes and mixins. In Proceedings of the 25th ACM SIGPLAN--SIGACT Symposium on Principles of Programming Languages, pages 171--183. ACM Press, 1998. Google Scholar
Digital Library
- The Fortress language specification. http://research.sun.com/projects/plrg/fortress0866.pdf.Google Scholar
- Kathleen Fisher and John Reppy. Statically typed traits. Technical Report TR--2003--13, University of Chicago, Department of Computer Science, December 2003.Google Scholar
- James Gosling, Bill Joy, Guy Steele, and Gilad Bracha. The Java Language Specification, Second Edition. Addison Wesley, 2000. Google Scholar
Digital Library
- James Gosling, Bill Joy, Guy Steele, and Gilad Bracha. The Java Language Specification (Third Edition). Addison Wesley, 2005. Google Scholar
Digital Library
- Dan Ingalls, Ted Kaehler, John Maloney, Scott Wallace, and Alan Kay. Back to the future: The story of Squeak, A practical Smalltalk written in itself. In Proceedings OOPSLA '97, ACM SIGPLAN Notices, pages 318--326. ACM Press, November 1997. Google Scholar
Digital Library
- Bertrand Meyer. Eiffel: The Language. Prentice-Hall, 1992. Google Scholar
Digital Library
- Bertrand Meyer. Object-Oriented Software Construction. Prentice-Hall, second edition, 1997. Google Scholar
Digital Library
- Tom Mens and Marc van Limberghen. Encapsulation and composition as orthogonal operators on mixins: A solution to multiple inheritance problems. Object Oriented Systems, 3(1):1--30, 1996.Google Scholar
- Oscar Nierstrasz, Stéphane Ducasse, and Nathanael Schärli. Flattening Traits. Journal of Object Technology, 5(4):129--148, May 2006.Google Scholar
Cross Ref
- Martin Odersky. Scala language secification v. 2.4. Technical report, Ecole Polytechnique Fédérale de Lausanne, 1015 Lausanne, Switzerland, March 2007.Google Scholar
- Jon G. Riecke and Christopher A. Stone. Privacy via subsumption. Inf. Comput., 172(1):2--28, 2002. Google Scholar
Digital Library
- John Reppy and Aaron Turon. A foundation for trait-based metaprogramming. In International Workshop on Foundations and Developments of Object-Oriented Languages, 2006.Google Scholar
- John Reppy and Aaron Turon. Metaprogramming with traits. In Proceedings of European Conference on Object-Oriented Programming (ECOOP'2007), 2007. Google Scholar
Digital Library
- Nathanael Schärli, Andrew P. Black, and Stéphane Ducasse. Object-oriented encapsulation for dynamically typed languages. In Proceedings of 18th International Conference on Object-Oriented Programming Systems, Languages and Applications (OOPSLA'04), pages 130--149, October 2004. Google Scholar
Digital Library
- The scala programming language. http://lamp.epl.ch/scala/.Google Scholar
- Charles Smith and Sophia Drossopoulou. Chai: Typed traits in Java. In Proceedings ECOOP 2005, 2005.Google Scholar
- Nathanael Schärli, Stéphane Ducasse, Oscar Nierstrasz, and Andrew Black. Traits: Composable units of behavior. In Proceedings of European Conference on Object-Oriented Programming (ECOOP'03), volume 2743 of LNCS, pages 248--274. Springer Verlag, July 2003.Google Scholar
Cross Ref
- Slate. http://slate.tunes.org.Google Scholar
- David Thomas and Andy Hunt. Programming Ruby. Addison Wesley, 2nd edition, 2005.Google Scholar
- Mario Wolczko. Encapsulation, delegation and inheritance in object-oriented languages. IEEE Software Engineering Journal, 7(2):95--102, March 1992. Google Scholar
Digital Library
Index Terms
User-changeable visibility: resolving unanticipated name clashes in traits
Recommendations
Object-oriented encapsulation for dynamically typed languages
OOPSLA '04: Proceedings of the 19th annual ACM SIGPLAN conference on Object-oriented programming, systems, languages, and applicationsEncapsulation in object-oriented languages has traditionally been based on static type systems. As a consequence, dynamically-typed languages have only limited support for encapsulation. This is surprising, considering that encapsulation is one of the ...
User-changeable visibility: resolving unanticipated name clashes in traits
OOPSLA '07: Proceedings of the 22nd annual ACM SIGPLAN conference on Object-oriented programming systems, languages and applicationsA trait is a unit of behaviour that can be composed with other traits and used by classes. Traits offer an alternative to multiple inheritance. Conflict resolution of traits, while flexible, does not completely handle accidental method name conflicts: ...
Object-oriented encapsulation for dynamically typed languages
OOPSLA '04Encapsulation in object-oriented languages has traditionally been based on static type systems. As a consequence, dynamically-typed languages have only limited support for encapsulation. This is surprising, considering that encapsulation is one of the ...







Comments