Modularizing Different Responsibilities into Separate Parallel Hierarchies

  • Francisco Ortin
  • Miguel Garcia
Part of the Communications in Computer and Information Science book series (CCIS, volume 275)

Abstract

When tangled inheritance hierarchies lead to code duplication, the Tease Apart Inheritance "big" refactoring is commonly used to create two parallel hierarchies, using delegation to invoke one from the other. Under these circumstances, the root class of the refactored hierarchy must be general enough to provide all its services to the other hierarchy, leading to meaningless interfaces that violate the Liskov substitution principle. In order to avoid this limitation, we propose a behavioral design pattern that allows the modularization of different responsibilities in separate hierarchies that collaborate to achieve a common goal. With this design, it is possible to use the specific interface of each class in the parallel hierarchy, without needing to define all the methods provided by every class in the hierarchy, and hence not violating the Liskov substitution principle. The proposed design is type safe and avoids the use of dynamic type checking and reflection; at compile time, the type system ensures that no type error will be produced dynamically.

Keywords

Design patterns refactoring software design parametric polymerphism generics 

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. 1.
    Hanson, D.R., Fraser, C.W.: A Retargetable C Compiler: Design and Implementation. Addison-Wesley Professional (1995)Google Scholar
  2. 2.
    Appel, A.W.: Modern Compiler Implementation in Java, 2nd edn. Cambridge University Press (2002)Google Scholar
  3. 3.
    Gamma, E., Helm, R., Johnson, R., Vlissides, J.: Design Patterns: Elements of Re-usable Object-Oriented Software. Addison Wesley (1994)Google Scholar
  4. 4.
    Watt, D., Brown, D.: Programming Language Processors in Java: Compilers and Interpreters. Prentice Hall (2000)Google Scholar
  5. 5.
    Lindholm, T., Yellin, F.: Java Virtual Machine Specification, 2nd edn. Prentice Hall (1999)Google Scholar
  6. 6.
    ECMA 335, European Computer Manufacturers Association (ECMA). Common Language Infrastructure (CLI), Partition IV: CIL Instruction Set, 4th edn. (2006)Google Scholar
  7. 7.
    Fowler, M., Beck, K., Brant, J., Opdyke, W., Roberts, D.: Refactoring: Improving the Design of Existing Code. Addison-Wesley Professional (1999)Google Scholar
  8. 8.
    Liskov, B.: Data Abstraction and Hierarchy. In: Conference on Object Oriented Programming Systems Languages and Applications (OOPSLA), Orlando, Florida, United States, pp. 17–34 (1987)Google Scholar
  9. 9.
    Ortin, F., Redondo, J.M., Perez-Schofield, J.B.G.: Efficient virtual machine support of runtime structural reflection. Science of Computer Programming 74(10), 836–860 (2009)MathSciNetMATHCrossRefGoogle Scholar
  10. 10.
    Canning, P., Cook, W., Hill, W., Walter, O., Mitchell, J.C.: F-bounded polymorphism for object-oriented programming. In: Proceedings of the Fourth International Conference on Functional Programming Languages and Computer Architecture, London, United Kingdom, pp. 273–280 (1989)Google Scholar
  11. 11.
    Odersky, M., Wadler, P.: Pizza into Java: Translating theory into practice. In: Proceedings of the 24th ACM Symposium on Principles of Programming Languages (POPL), Paris, France, pp. 146–159 (1997)Google Scholar
  12. 12.
    JSR 294 Sun Microsystems, JSR 294: Improved Modularity Support in the Java Programming Language (2007), http://jcp.org/en/jsr/detail?id=294
  13. 13.
    Meyer, J.: Jasmin Instructions (1996), http://jasmin.sourceforge.net/instructions.html
  14. 14.
    Ortin, F., Zapico, D., Perez-Schofield, J.B.G., Garcia, M.: Including both Static and Dynamic Typing in the same Programming Language. IET Software 4(4), 268–282 (2010)CrossRefGoogle Scholar
  15. 15.
    Hugunin, J.: Bringing dynamic languages to .NET with the DLR. In: Proceedings of the Symposium on Dynamic Languages, Montreal, Quebec, Canada, p. 101 (2007)Google Scholar
  16. 16.
    Wadler, P.: The expression problem. Posted on the Java Genericity Mailing List (1998)Google Scholar
  17. 17.
    Torgersen, M.: The Expression Problem Revisited. In: Vetta, A. (ed.) ECOOP 2004. LNCS, vol. 3086, pp. 123–146. Springer, Heidelberg (2004)CrossRefGoogle Scholar
  18. 18.
    Nielsen, E.T., Larsen, K.A., Markert, S., Kjaer, K.E.: The Expression Problem in Scala. Technical Report, Aarhus University (May 31, 2005)Google Scholar
  19. 19.
    Ernst, E.: Higher-Order Hierarchies. In: Cardelli, L. (ed.) ECOOP 2003. LNCS, vol. 2743, pp. 303–329. Springer, Heidelberg (2003)CrossRefGoogle Scholar
  20. 20.
    Ortin, F., Garcia, M.: Union and intersection types to support both dynamic and static typing. Information Processing Letters 111(6), 278–286 (2011)MathSciNetCrossRefGoogle Scholar
  21. 21.
    Redondo, J., Ortin, F., Cueva, J.: Optimizing Reflective Primitives of Dynamic Languages. International Journal of Software Engineering and Knowledge Engineering 18(6), 759–783 (2008)CrossRefGoogle Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2013

Authors and Affiliations

  • Francisco Ortin
    • 1
  • Miguel Garcia
    • 1
  1. 1.Computer Science DepartmentUniversity of OviedoOviedoSpain

Personalised recommendations