Challenges in the Design of the Package Template Mechanism

  • Eyvind W. Axelsen
  • Fredrik Sørensen
  • Stein Krogdahl
  • Birger Møller-Pedersen
Part of the Lecture Notes in Computer Science book series (LNCS, volume 7271)


Package Templates are a mechanism for writing modules meant for reuse, where each module (template) consists of a collection of classes. A package template must be instantiated in a program at compile time to form a set of ordinary classes, and during instantiation, the classes may be adapted by means of renaming, adding attributes (fields and methods), and supplying type parameters. An approach like this naturally gives rise to two distinct dimensions along which classes can be extended. One is the ordinary subclass dimension, while the other is comprised of the ability to adapt classes during instantiations. The latter dimension also allows for a form of static multiple inheritance, in that classes from two or more instantiations may be merged to form a new class. This will be handled entirely at compile time, and the new class will have all the attributes from the merged classes and also the attributes added in the instantiating template. This paper discusses how these two dimensions play together in the different mechanisms that make up the Package Templates approach, and the design considerations involved. The paper also argues that the compromise made in Package Templates between simplicity of the type system on the one hand and expressiveness on the other is, for most purposes, better than similar approaches based on virtual classes.


Programming Languages Language Constructs Object-oriented Programming Modules Packages Modularization Inheritance Templates 


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.


  1. 1.
    Dahl, O.J., Myhrhaug, B., Nygaard, K.: Simula 67 common base language. Technical Report Publication No. S-22 (Revised edition of publication S-2), Norwegian Computing Center (1970)Google Scholar
  2. 2.
    Stroustrup, B.: Multiple inheritance for C++. Computing Systems 2(4), 367–395 (1989)Google Scholar
  3. 3.
    Bracha, G.: Generics in the Java programming language. Technical report, Sun Microsystems, Santa Clara, CA (2004),
  4. 4.
    Madsen, O.L., Møller-Pedersen, B.: Virtual classes: a powerful mechanism in object-oriented programming. In: OOPSLA 1989: Conference Proceedings on Object-Oriented Programming Systems, Languages and Applications, pp. 397–406. ACM, New York (1989)CrossRefGoogle Scholar
  5. 5.
    Madsen, O.L., Møller-Pedersen, B., Nygaard, K.: Object-oriented programming in the BETA programming language. ACM Press/Addison-Wesley Publishing Co., New York, NY, USA (1993)Google Scholar
  6. 6.
    Kiczales, G., Lamping, J., Menhdhekar, A., Maeda, C., Lopes, C., 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
  7. 7.
    Schärli, N., Ducasse, S., Nierstrasz, O., Black, A.: Traits: Composable Units of Behavior. In: Cardelli, L. (ed.) ECOOP 2003. LNCS, vol. 2743, pp. 327–339. Springer, Heidelberg (2003)Google Scholar
  8. 8.
    Bracha, G., Cook, W.: Mixin-based inheritance. In: Meyrowitz, N. (ed.) OOPSLA/ECOOP, Ottawa, Canada, pp. 303–311. ACM Press (1990)Google Scholar
  9. 9.
    Krogdahl, S., Møller-Pedersen, B., Sørensen, F.: Exploring the use of package templates for flexible re-use of collections of related classes. Journal of Object Technology 8(7), 59–85 (2009)CrossRefGoogle Scholar
  10. 10.
    Sørensen, F., Axelsen, E.W., Krogdahl, S.: Reuse and combination with package templates. In: Proceedings of the 4th Workshop on MechAnisms for SPEcialization, Generalization and inHerItance, MASPEGHI 2010, pp. 3:1–3:5. ACM, New York (2010)CrossRefGoogle Scholar
  11. 11.
    Axelsen, E.W., Krogdahl, S.: Groovy package templates: supporting reuse and runtime adaption of class hierarchies. In: DLS 2009: Proceedings of the 5th Symposium on Dynamic Languages, pp. 15–26. ACM, New York (2009)CrossRefGoogle Scholar
  12. 12.
    Axelsen, E.W., Krogdahl, S., Møller-Pedersen, B.: Controlling dynamic module composition through an extensible meta-level API. In: DLS 2010: Proceedings of the 6th Symposium on Dynamic Languages. ACM, New York (2010)Google Scholar
  13. 13.
    Ernst, E.: Gbeta - a language with virtual attributes, block structure, and propagating, dynamic inheritance (1999)Google Scholar
  14. 14.
    Aracic, I., Gasiunas, V., Awasthi, P., Ostermann, K.: An Overview of CaesarJ. In: Rashid, A., Aksit, M. (eds.) Transactions on AOSD I. LNCS, vol. 3880, pp. 135–173. Springer, Heidelberg (2006)CrossRefGoogle Scholar
  15. 15.
    Nystrom, N., Chong, S., Myers, A.C.: Scalable extensibility via nested inheritance. In: OOPSLA 2004: Proceedings of the 19th Annual ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications, pp. 99–115. ACM, New York (2004)CrossRefGoogle Scholar
  16. 16.
    Nystrom, N., Qi, X., Myers, A.C.: J&: nested intersection for scalable software composition. In: OOPSLA 2006: Proceedings of the 21st Annual ACM SIGPLAN Conference on Object-Oriented Programming Systems, Languages, and applications, pp. 21–36. ACM, New York (2006)CrossRefGoogle Scholar
  17. 17.
    Bracha, G., von der Ahé, P., Bykov, V., Kashai, Y., Maddox, W., Miranda, E.: Modules as Objects in Newspeak. In: D’Hondt, T. (ed.) ECOOP 2010. LNCS, vol. 6183, pp. 405–428. Springer, Heidelberg (2010)CrossRefGoogle Scholar
  18. 18.
    Compagnoni, A.B., Pierce, B.C.: Higher-order intersection types and multiple inheritance. Mathematical Structures in Computer Science 6, 469–501 (1996)MathSciNetzbMATHGoogle Scholar
  19. 19.
    Ernst, E., Ostermann, K., Cook, W.R.: A virtual class calculus. In: Conference record of the 33rd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2006, pp. 270–282. ACM, New York (2006)CrossRefGoogle Scholar
  20. 20.
    Torgersen, M.: The Expression Problem Revisited Four New Solutions Using Generics. In: Odersky, M. (ed.) ECOOP 2004. LNCS, vol. 3086, pp. 123–146. Springer, Heidelberg (2004)CrossRefGoogle Scholar
  21. 21.
    Ernst, E.: The expression problem, scandinavian style. In: Lahire, P., Arévalo, G., Astudillo, H., Black, A.P., Ernst, E., Huchard, M., Sakkinen, M., Valtchev, P. (eds.) MASPEGHI 2004 (2004)Google Scholar
  22. 22.
    Gamma, E., Helm, R., Johnson, R., Vlissides, J.: Design Patterns -Elements of Reusable Object-Oriented Software. Addison-Wesley (1994)Google Scholar
  23. 23.
    Ekman, T., Hedin, G.: The JastAdd extensible Java compiler. SIGPLAN Not. 42, 1–18 (2007)CrossRefGoogle Scholar
  24. 24.
    Ekman, T., Hedin, G.: The JastAdd system — modular extensible compiler construction. Sci. Comput. Program. 69, 14–26 (2007)MathSciNetzbMATHCrossRefGoogle Scholar
  25. 25.
    Bergel, A., Ducasse, S., Nierstrasz, O., Wuyts, R.: Stateful traits and their formalization. Computer Languages, Systems & Structures 34, 83–108 (2008)CrossRefGoogle Scholar
  26. 26.
    Nierstrasz, O., Ducasse, S., Reichhart, S., Schärli, N.: Adding Traits to (Statically Typed) Languages. Technical Report IAM-05-006, Institut für Informatik, Universität Bern, Switzerland (2005)Google Scholar
  27. 27.
    Ernst, E.: Family polymorphism. In: Lindskov Knudsen, J. (ed.) ECOOP 2001. LNCS, vol. 2072, pp. 303–326. Springer, Heidelberg (2001)CrossRefGoogle Scholar
  28. 28.
    Saito, C., Igarashi, A., Viroli, M.: Lightweight family polymorphism. J. Funct. Program. 18, 285–331 (2008)MathSciNetzbMATHCrossRefGoogle Scholar
  29. 29.
    Igarashi, A., Viroli, M.: Variant path types for scalable extensibility. In: Proceedings of the 22nd Annual ACM SIGPLAN Conference on Object-Oriented Programming Systems and Applications, OOPSLA 2007, pp. 113–132. ACM, New York (2007)CrossRefGoogle Scholar
  30. 30.
    Bergel, A., Ducasse, S., Nierstrasz, O.: Classbox/J: controlling the scope of change in Java. In: Proceedings of the 20th Annual ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications, OOPSLA 2005, pp. 177–189. ACM, New York (2005)CrossRefGoogle Scholar
  31. 31.
    Clifton, C., Millstein, T., Leavens, G.T., Chambers, C.: MultiJava: Design rationale, compiler implementation, and applications. ACM Trans. Program. Lang. Syst. 28, 517–575 (2006)CrossRefGoogle Scholar
  32. 32.
    Warth, A., Stanojević, M., Millstein, T.: Statically scoped object adaptation with expanders. In: Proceedings of the 21st Annual ACM SIGPLAN Conference on Object-Oriented Programming Systems, Languages, and Applications, OOPSLA 2006, pp. 37–56. ACM, New York (2006)CrossRefGoogle Scholar
  33. 33.
    Ichisugi, Y., Tanaka, A.: Difference-Based Modules: A Class-Independent Module Mechanism. In: Magnusson, B. (ed.) ECOOP 2002. LNCS, vol. 2374, pp. 62–88. Springer, Heidelberg (2002)CrossRefGoogle Scholar
  34. 34.
    Corradi, A., Servetto, M., Zucca, E.: DeepFJig - modular composition of nested classes. In: 2010 International Workshop on Foundations of Object-Oriented Languages, FOOL 2010 (2010)Google Scholar
  35. 35.
    Ledgard, H.: Reference Manual for the ADA Programming Language. Springer-Verlag New York, Inc., Secaucus (1983)Google Scholar
  36. 36.
    Barnes, J.: Programming in Ada95. Addison Wesley Longman Publishing Co., Inc., Redwood City (1995)Google Scholar
  37. 37.
    Colyer, A.: AspectJ. In: Aspect-Oriented Software Development, pp. 123–143. Addison-Wesley (2005)Google Scholar
  38. 38.
    Filman, R.E., Friedman, D.P.: Aspect-oriented programming is quantification and obliviousness. In: Filman, R.E., Elrad, T., Clarke, S., Akşit, M. (eds.) AOSD, pp. 21–31. Addison-Wesley (2005)Google Scholar
  39. 39.
    Störzer, M., Koppen, C.: Pcdiff: Attacking the fragile pointcut problem, abstract. In: EIWAS, Berlin, Germany (2004)Google Scholar
  40. 40.
    Axelsen, E.W., Sørensen, F., Krogdahl, S.: A reusable observer pattern implementation using package templates. In: ACP4IS 2009: Proceedings of the 8th Workshop on Aspects, Components, and Patterns for Infrastructure Software, pp. 37–42. ACM, New York (2009)CrossRefGoogle Scholar
  41. 41.
    Hannemann, J., Kiczales, G.: Design pattern implementation in Java and AspectJ. SIGPLAN Not. 37, 161–173 (2002)CrossRefGoogle Scholar
  42. 42.
    Mezini, M., Ostermann, K.: Conquering aspects with Caesar. In: AOSD 2003, pp. 90–99. ACM, New York (2003)CrossRefGoogle Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2012

Authors and Affiliations

  • Eyvind W. Axelsen
    • 1
  • Fredrik Sørensen
    • 1
  • Stein Krogdahl
    • 1
  • Birger Møller-Pedersen
    • 1
  1. 1.University of OsloOsloNorway

Personalised recommendations