Scala Roles: Reusable Object Collaborations in a Library

  • Michael Pradel
  • Martin Odersky
Conference paper
Part of the Communications in Computer and Information Science book series (CCIS, volume 47)


Purely class-based implementations of object-oriented software are often inappropriate for reuse. In contrast, the notion of objects playing roles in a collaboration has been proven to be a valuable reuse abstraction. However, existing solutions to enable role-based programming tend to require vast extensions of the underlying programming language, and thus, are difficult to use in every day work. We present a programming technique, based on dynamic proxies, that allows to augment an object’s type at runtime while preserving strong static type safety. It enables role-based implementations that lead to more reuse and better separation of concerns.


Object Identity Role Type Core Object Arbitrary Object Type Hierarchy 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.


  1. 1.
    Reenskaug, T., Wold, P., Lehne, O.A.: Working with Objects, The OOram Software Engineering Method. Manning (1996)Google Scholar
  2. 2.
    Riehle, D.: Framework Design: A Role Modeling Approach. PhD thesis, ETH Zürich (2000)Google Scholar
  3. 3.
    Steimann, F.: On the representation of roles in object-oriented and conceptual modelling. Data & Knowledge Engineering 35(1), 83–106 (2000)zbMATHCrossRefGoogle Scholar
  4. 4.
    Object Management Group OMG: OMG Unified Modeling Language (OMG UML), Superstructure, v2.1.2 (November 2007)Google Scholar
  5. 5.
    Bäumer, D., Riehle, D., Siberski, W., Wulf, M.: Role Object. In: Pattern Languages of Program Design 4, pp. 15–32. Addison-Wesley, Reading (2000)Google Scholar
  6. 6.
    Herrmann, S.: A precise model for contextual roles: The programming language ObjectTeams/Java. Applied Ontology 2(2), 181–207 (2007)Google Scholar
  7. 7.
    Smaragdakis, Y., Batory, D.: Mixin layers: An object-oriented implementation technique for refinements and collaboration-based designs. ACM Transactions on Software Engineering and Methodology (TOSEM) 11(2), 215–255 (2002)CrossRefGoogle Scholar
  8. 8.
    Odersky, M.: Scala Language Specification, Version 2.7 (May 2008)Google Scholar
  9. 9.
    Guarino, N.: Concepts, attributes and arbitrary relations: Some linguistic and ontological criteria for structuring knowledge bases. Data & Knowledge Engineering 8(3), 249–261 (1992)CrossRefGoogle Scholar
  10. 10.
    Kristensen, B.B., Østerbye, K.: Roles: Conceptual abstraction theory and practical language issues. Theory and Practice of Object Systems 2(3), 143–160 (1996)CrossRefGoogle Scholar
  11. 11.
    Gamma, E., Helm, R., Johnson, R., Vlissides, J.: Design Patterns: Elements of Reusable Object-Oriented Software. Addison-Wesley, Reading (1995)Google Scholar
  12. 12.
    Harrison, W.: Homepage on subject-oriented programming and design patterns (1997),
  13. 13.
    Odersky, M., Spoon, L., Venners, B.: Programming in Scala, A comprehensive step-by-step guide. Artima (2008)Google Scholar
  14. 14.
    Riehle, D.: Composite design patterns. In: Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA 1997), pp. 218–228. ACM, New York (1997)Google Scholar
  15. 15.
    Herrmann, S., Hundt, C., Mehner, K.: Translation polymorphism in Object Teams. Technical Report 2004/05, TU Berlin (2004)Google Scholar
  16. 16.
    Kiczales, G., Lamping, J., Mendhekar, A., Maeda, C., Lopes, C.V., Loingtier, J.M., Irwin, J.: Aspect-oriented programming. In: Aksit, M., Matsuoka, S. (eds.) ECOOP 1997. LNCS, vol. 1241, pp. 220–242. Springer, Heidelberg (1997)CrossRefGoogle Scholar
  17. 17.
    Kendall, E.A.: Role model designs and implementations with aspect-oriented programming. SIGPLAN Notices 34(10), 353–369 (1999)CrossRefMathSciNetGoogle Scholar
  18. 18.
    Hannemann, J., Kiczales, G.: Design pattern implementation in Java and AspectJ. SIGPLAN Notices 37(11), 161–173 (2002)CrossRefGoogle Scholar
  19. 19.
    Rumbaugh, J.E.: Relations as semantic constructs in an object-oriented language. In: Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA 1987), pp. 466–481 (1987)Google Scholar
  20. 20.
    Bierman, G.M., Wren, A.: First-class relationships in an object-oriented language. In: Black, A.P. (ed.) ECOOP 2005. LNCS, vol. 3586, pp. 262–286. Springer, Heidelberg (2005)Google Scholar
  21. 21.
    Balzer, S., Gross, T.R., Eugster, P.: A relational model of object collaborations and its use in reasoning about relationships. In: Ernst, E. (ed.) ECOOP 2007. LNCS, vol. 4609, pp. 323–346. Springer, Heidelberg (2007)CrossRefGoogle Scholar
  22. 22.
    Pradel, M.: Explicit relations with roles - a library approach. In: Workshop on Relationships and Associations in Object-Oriented Languages (RAOOL) at OOPSLA 2008 (2008)Google Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2009

Authors and Affiliations

  • Michael Pradel
    • 1
  • Martin Odersky
    • 2
  1. 1.TU DresdenGermany
  2. 2.EPFLSwitzerland

Personalised recommendations