Adding State and Visibility Control to Traits Using Lexical Nesting

  • Tom Van Cutsem
  • Alexandre Bergel
  • Stéphane Ducasse
  • Wolfgang De Meuter
Part of the Lecture Notes in Computer Science book series (LNCS, volume 5653)

Abstract

Traits are reusable building blocks that can be composed to share methods across unrelated class hierarchies. Original traits are stateless and cannot express visibility control for methods. Two extensions, stateful traits and freezable traits, have been proposed to overcome these limitations. However, these extensions introduce complexity and have not yet been combined to simultaneously add both state and visibility control to traits.

This paper revisits the addition of state and visibility control to traits. Rather than extending the original traits model with additional operations, we allow traits to be lexically nested within other modules. Traits can then have (shared) state and visibility control by hiding variables or methods in their lexical scope. Although the Traits’ “flattening property” has to be revisited, the combination of traits with lexical nesting results in a simple and expressive trait model. We discuss an implementation of the model in AmbientTalk and specify its operational semantics.

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. 1.
  2. 2.
    Ingalls, D., Kaehler, T., Maloney, J., Wallace, S., Kay, A.: Back to the future: The story of Squeak, a practical Smalltalk written in itself. In: Proceedings of the 12th ACM SIGPLAN conference on Object-oriented programming, systems, languages, and applications, pp. 318–326. ACM Press, New York (1997)CrossRefGoogle Scholar
  3. 3.
    Flatt, M., Finder, R.B., Felleisen, M.: Scheme with classes, mixins and traits. In: AAPLAS 2006 (2006)Google Scholar
  4. 4.
    The Fortress language specification, http://research.sun.com/projects/plrg/fortress0866.pdf
  5. 5.
    Fisher, K., Reppy, J.: Statically typed traits. Technical Report TR-2003-13, University of Chicago, Department of Computer Science (December 2003)Google Scholar
  6. 6.
    Smith, C., Drossopoulou, S.: chai: Traits for java-like languages. In: Black, A.P. (ed.) ECOOP 2005. LNCS, vol. 3586, pp. 453–478. Springer, Heidelberg (2005)CrossRefGoogle Scholar
  7. 7.
    Liquori, L., Spiwack, A.: FeatherTrait: A modest extension of Featherweight Java. ACM Transactions on Programming Languages and Systems (TOPLAS) 30(2), 1–32 (2008)CrossRefMATHGoogle Scholar
  8. 8.
    Reppy, J., Turon, A.: Metaprogramming with traits. In: Ernst, E. (ed.) ECOOP 2007. LNCS, vol. 4609, pp. 373–398. Springer, Heidelberg (2007)CrossRefGoogle Scholar
  9. 9.
    Bergel, A., Ducasse, S., Nierstrasz, O., Wuyts, R.: Stateful traits and their formalization. Journal of Computer Languages, Systems and Structures 34(2-3), 83–108 (2007)CrossRefGoogle Scholar
  10. 10.
    Ducasse, S., Wuyts, R., Bergel, A., Nierstrasz, O.: User-changeable visibility: Resolving unanticipated name clashes in traits. In: Proceedings of 22nd International Conference on Object-Oriented Programming, Systems, Languages, and Applications, pp. 171–190. ACM Press, New York (2007)Google Scholar
  11. 11.
    Bak, L., Bracha, G., Grarup, S., Griesemer, R., Griswold, D., Hölzle, U.: Mixins in Strongtalk. In: ECOOP 2002 Workshop on Inheritance (2002)Google Scholar
  12. 12.
    Ducasse, S., Nierstrasz, O., Schärli, N., Wuyts, R., Black, A.: Traits: A mechanism for fine-grained reuse. ACM Transactions on Programming Languages and Systems (TOPLAS) 28(2), 331–388 (2006)CrossRefGoogle Scholar
  13. 13.
    Schärli, N., Ducasse, S., Nierstrasz, O., Black, A.: Traits: Composable units of behavior. In: Cardelli, L. (ed.) ECOOP 2003. LNCS, vol. 2743, pp. 248–274. Springer, Heidelberg (2003)CrossRefGoogle Scholar
  14. 14.
    Reppy, J., Turon, A.: A foundation for trait-based metaprogramming. In: International Workshop on Foundations and Developments of Object-Oriented Languages (2006)Google Scholar
  15. 15.
    Mens, T., van Limberghen, M.: Encapsulation and composition as orthogonal operators on mixins: A solution to multiple inheritance problems. Object Oriented Systems 3(1), 1–30 (1996)Google Scholar
  16. 16.
    Ungar, D., Chambers, C., Chang, B.W., Hölzle, U.: Organizing programs without classes. LISP and Symbolic Computation 4(3) (1991)Google Scholar
  17. 17.
    Reddy, U.: Objects as closures: abstract semantics of object-oriented languages. In: LFP 1988: Proceedings of the ACM conference on LISP and functional programming, pp. 289–297. ACM, New York (1988)CrossRefGoogle Scholar
  18. 18.
    Abelson, H., Sussman, G.J., Sussman, J.: Structure and interpretation of computer programs. MIT electrical engineering and computer science series. McGraw-Hill, New York (1991)CrossRefMATHGoogle Scholar
  19. 19.
    Dickey, K.: Scheming with objects. AI Expert 7(10), 24–33 (1992)Google Scholar
  20. 20.
    Black, A., Hutchinson, N., Jul, E., Levy, H.: Object structure in the Emerald system. In: Proceedings OOPSLA 1986, ACM SIGPLAN Notices, vol. 21, pp. 78–86 (November 1986)Google Scholar
  21. 21.
    International, E.C.M.A.: ECMA-262: ECMAScript Language Specification, 3rd edn. ECMA (European Association for Standardizing Information and Communication Systems), Geneva, Switzerland (December 1999)Google Scholar
  22. 22.
    Madsen, O.L., Moller-Pedersen, B., Nygaard, K.: Object-Oriented Programming in the Beta Programming Language. Addison Wesley, Reading (1993)Google Scholar
  23. 23.
    Miller, M.S.: Robust Composition: Towards a Unified Approach to Access Control and Concurrency Control. PhD thesis, Johns Hopkins University, Baltimore, Maryland, USA (May 2006)Google Scholar
  24. 24.
    Bracha, G.: On the interaction of method lookup and scope with inheritance and nesting. In: 3rd ECOOP Workshop on Dynamic Languages and Applications (2007)Google Scholar
  25. 25.
    Dedecker, J., Cutsem, T.V., Mostinckx, S., Theo D’Hondt, W.D.M.: Ambient-oriented programming in ambienttalk. In: Thomas, D. (ed.) ECOOP 2006. LNCS, vol. 4067, pp. 230–254. Springer, Heidelberg (2006)CrossRefGoogle Scholar
  26. 26.
    Van Cutsem, T., Mostinckx, S., Boix, E., Dedecker, J., De Meuter, W.: Ambienttalk: Object-oriented event-driven programming in mobile ad hoc networks. In: XXVI International Conference of the Chilean Society of Computer Science, 2007. SCCC 2007, pp. 3–12 (November 2007)Google Scholar
  27. 27.
    Ungar, D., Smith, R.B.: Self: The power of simplicity. In: Proceedings OOPSLA 1987, ACM SIGPLAN Notices, vol. 22, pp. 227–242 (December 1987)Google Scholar
  28. 28.
    Lieberman, H.: Using prototypical objects to implement shared behavior in object oriented systems. In: Proceedings OOPSLA 1986, ACM SIGPLAN Notices, vol. 21, pp. 214–223 (December 1986)Google Scholar
  29. 29.
    Maloney, J.H., Smith, R.B.: Directness and liveness in the morphic user interface construction environment. In: UIST 1995: Proceedings of the 8th annual ACM symposium on User interface and software technology, pp. 21–28. ACM, New York (1995)Google Scholar
  30. 30.
    Smith, R.B., Ungar, D.: Programming as an experience: The inspiration for self. In: Olthoff, W. (ed.) ECOOP 1995. LNCS, vol. 952, pp. 303–330. Springer, Heidelberg (1995)Google Scholar
  31. 31.
    Anderson, C., Drossopoulou, S.: delta an imperative object based calculus. In: Proceedings of USE 2002 (2002)Google Scholar
  32. 32.
    Bettini, L., Bono, V.: Type Safe Dynamic Object Delegation in Class-based Languages. In: Proc. of PPPJ, Principles and Practice of Programming in Java. ACM Press, New York (2008)Google Scholar
  33. 33.
    Bono, V., Fisher, K.: An imperative, first-order calculus with object extension. In: Proceedings of the 12th European Conference on Object-Oriented Programming, London, UK, pp. 462–497. Springer, Heidelberg (1998)Google Scholar
  34. 34.
    Flatt, M., Krishnamurthi, S., Felleisen, M.: Classes and mixins. In: Proceedings of the 25th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, pp. 171–183. ACM Press, New York (1998)CrossRefGoogle Scholar
  35. 35.
    Felleisen, M., Hieb, R.: The revised report on the syntactic theories of sequential control and state. Theor. Comput. Sci. 103(2), 235–271 (1992)MathSciNetCrossRefMATHGoogle Scholar
  36. 36.
    Bracha, G.: The Programming Language Jigsaw: Mixins, Modularity and Multiple Inheritance. PhD thesis, Dept. of Computer Science, University of Utah (1992)Google Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2009

Authors and Affiliations

  • Tom Van Cutsem
    • 1
  • Alexandre Bergel
    • 2
  • Stéphane Ducasse
    • 2
  • Wolfgang De Meuter
    • 1
  1. 1.Programming Technology LabVrije Universiteit BrusselBelgium
  2. 2.RMoD research group, INRIA LilleFrance

Personalised recommendations