Covariant Conversions (CoCo): A Design Pattern for Type-Safe Modular Software Evolution in Object-Oriented Systems

Authors Jan Bessai, George T. Heineman, Boris Düdder

Thumbnail PDF


  • Filesize: 2.16 MB
  • 25 pages

Document Identifiers

Author Details

Jan Bessai
  • Technische Universität Dortmund, Germany
George T. Heineman
  • Worcester Polytechnic Institute, MA, USA
Boris Düdder
  • University of Copenhagen, Denmark


We would like to thank the reviewers of earlier versions of this paper for their carefully thought out, detailed reviews, as well as the many constructive remarks. They helped to improve our presentation, the artifacts, and the pattern drastically. Special thanks go to the reviewer who suggested to mitigate "parameterization boilerplate" with type members.

Cite AsGet BibTex

Jan Bessai, George T. Heineman, and Boris Düdder. Covariant Conversions (CoCo): A Design Pattern for Type-Safe Modular Software Evolution in Object-Oriented Systems. In 35th European Conference on Object-Oriented Programming (ECOOP 2021). Leibniz International Proceedings in Informatics (LIPIcs), Volume 194, pp. 4:1-4:25, Schloss Dagstuhl – Leibniz-Zentrum für Informatik (2021)


Software evolution is an essential challenge for all software engineers, typically addressed solely using code versioning systems and language-specific code analysis tools. Most versioning systems view the evolution of a system as a directed acyclic graph of steps, with independent branches that could be merged. What these systems fail to provide is the ability to ensure stable APIs or that each subsequent evolution represents a cohesive extension yielding a valid system. Modular software evolution ensures that APIs remain stable, which is achieved by ensuring that only additional methods, fields, and data types are added, while treating existing modules through blackbox interfaces. Even with these restrictions, it must be possible to add new variations, fields, and methods without extensive duplication of prior module code. In contrast to most literature, our focus is on ensuring modular software evolution using mainstream object-oriented programming languages, instead of resorting to novel language extensions. We present a novel CoCo design pattern that supports type-safe covariantly overridden convert methods to transform earlier data type instances into their newest evolutionary representation to access operations that had been added later. CoCo supports both binary methods and producer methods. We validate and contrast our approach using a well-known compiler construction case study that other researchers have also investigated for modular evolution. Our resulting implementation relies on less boilerplate code, is completely type-safe, and allows clients to use normal object-oriented calling conventions. We also compare CoCo with existing approaches to the Expression Problem. We conclude by discussing how CoCo could change the direction of currently proposed Java language extensions to support closed-world assumptions about data types, as borrowed from functional programming.

Subject Classification

ACM Subject Classification
  • Software and its engineering → Software evolution
  • Software and its engineering → Design patterns
  • Software and its engineering → Abstraction, modeling and modularity
  • Expression problem
  • software evolution
  • type safety
  • producer method
  • binary method


  • Access Statistics
  • Total Accesses (updated on a weekly basis)
    PDF Downloads


  1. Nada Amin, Samuel Grütter, Martin Odersky, Tiark Rompf, and Sandro Stucki. The essence of dependent object types. In Sam Lindley, Conor McBride, Philip W. Trinder, and Donald Sannella, editors, A List of Successes That Can Change the World - Essays Dedicated to Philip Wadler on the Occasion of His 60th Birthday, volume 9600 of Lecture Notes in Computer Science, pages 249-272. Springer, 2016. URL:
  2. Jan Bessai, George Heineman, and Boris Düdder. JanBessai/ecoop2021artifacts: State published with paper, 2021. URL:
  3. Kim B. Bruce. Some challenging typing issues in object-oriented languages. Electron. Notes Theor. Comput. Sci., 82(7):1-29, 2003. URL:
  4. William R. Cook, Walter L. Hill, and Peter S. Canning. Inheritance is not subtyping. In Frances E. Allen, editor, Conference Record of the Seventeenth Annual ACM Symposium on Principles of Programming Languages, San Francisco, California, USA, January 1990, pages 125-135. ACM Press, 1990. URL:
  5. Bruno C. d. S. Oliveira. Modular visitor components. In Sophia Drossopoulou, editor, ECOOP 2009 - Object-Oriented Programming, 23rd European Conference, Genoa, Italy, July 6-10, 2009. Proceedings, volume 5653 of Lecture Notes in Computer Science, pages 269-293. Springer, 2009. URL:
  6. Al Danial. Cloc code analysis tool, September 2020. URL:
  7. Erik Ernst. Family polymorphism. In Jørgen Lindskov Knudsen, editor, ECOOP 2001 - Object-Oriented Programming, 15th European Conference, Budapest, Hungary, June 18-22, 2001, Proceedings, volume 2072 of Lecture Notes in Computer Science, pages 303-326. Springer, 2001. URL:
  8. M. Fowler. Inversion of Control Containers and the Dependency Injection pattern, 2004. URL:
  9. Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides. Design patterns: elements of reusable object-oriented software. Addison-Wesley Longman Publishing Co., Inc., 1995. Google Scholar
  10. Brian Goetz and Gavin Bierman. JEP 394: Pattern matching for instanceof. Technical report, Open JDK, Oracle Corporation, 2021. URL:
  11. Guice Framework for Java, 2021. URL:
  12. William Harrison, David Lievens, and Fabio Simeoni. Safer typing of complex API usage through Java generics. In Proceedings of the 7th International Conference on Principles and Practice of Programming in Java, PPPJ '09, page 67–75, New York, NY, USA, 2009. Association for Computing Machinery. URL:
  13. Robert Heim, Pedram Mir Seyed Nazari, Bernhard Rumpe, and Andreas Wortmann. Compositional language engineering using generated, extensible, static type-safe visitors. In Andrzej Wasowski and Henrik Lönn, editors, Modelling Foundations and Applications - 12th European Conference, ECMFA@STAF 2016, Vienna, Austria, July 6-7, 2016, Proceedings, volume 9764 of Lecture Notes in Computer Science, pages 67-82. Springer, 2016. URL:
  14. Atsushi Igarashi and Mirko Viroli. Variant path types for scalable extensibility. In Richard P. Gabriel, David F. Bacon, Cristina Videira Lopes, and Guy L. Steele Jr., editors, Proceedings of the 22nd Annual ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications, OOPSLA 2007, October 21-25, 2007, Montreal, Quebec, Canada, pages 113-132. ACM, 2007. URL:
  15. Frederick P. Brooks Jr. The mythical man-month (Anniversary Ed.). Addison-Wesley Longman Publishing Co., Inc., 1995. Google Scholar
  16. Oleg Kiselyov. Typed tagless final interpreters. In Jeremy Gibbons, editor, Generic and Indexed Programming - International Spring School, SSGIP 2010, Oxford, UK, March 22-26, 2010, Revised Lectures, volume 7470 of Lecture Notes in Computer Science, pages 130-174. Springer, 2010. URL:
  17. Shriram Krishnamurthi, Matthias Felleisen, and Daniel P. Friedman. Synthesizing object-oriented and functional design to promote re-use. In Eric Jul, editor, ECOOP'98 - Object-Oriented Programming, 12th European Conference, Brussels, Belgium, July 20-24, 1998, Proceedings, volume 1445 of Lecture Notes in Computer Science, pages 91-113. Springer, 1998. URL:
  18. Manuel Leduc, Thomas Degueule, Benoît Combemale, Tijs van der Storm, and Olivier Barais. Revisiting visitors for modular extension of executable DSMLs. In 20th ACM/IEEE International Conference on Model Driven Engineering Languages and Systems, MODELS 2017, Austin, TX, USA, September 17-22, 2017, pages 112-122. IEEE Computer Society, 2017. URL:
  19. Shayan Najd and Simon Peyton Jones. Trees that grow. J. Univers. Comput. Sci., 23(1):42-62, 2017. URL:
  20. Bruno C. d. S. Oliveira and William R. Cook. Extensibility for the masses. In James Noble, editor, ECOOP 2012 - Object-Oriented Programming, pages 2-27, Berlin, Heidelberg, 2012. Springer Berlin Heidelberg. Google Scholar
  21. Lionel Parreaux. What is type projection in Scala, and why is it unsound?, 2019. Blog Entry. URL:
  22. Benjamin C. Pierce. Types and programming languages. MIT Press, 2002. URL:
  23. Sukyoung Ryu. ThisType for object-oriented languages: From theory to practice. ACM Trans. Program. Lang. Syst., 38(3):8:1-8:66, 2016. URL:
  24. Chieri Saito, Atsushi Igarashi, and Mirko Viroli. Lightweight family polymorphism. J. Funct. Program., 18(3):285-331, 2008. URL:
  25. Stefan Sobernig. Variable Domain-specific Software Languages with DjDSL - Design and Implementation. Springer, 2020. URL:
  26. Nicolas Stucki, Paolo G. Giarrusso, and Martin Odersky. Truly abstract interfaces for algebraic data types: the extractor typing problem. In Sebastian Erdweg and Bruno C. d. S. Oliveira, editors, Proceedings of the 9th ACM SIGPLAN International Symposium on Scala, SCALA@ICFP 2018, St. Louis, MO, USA, September 28, 2018, pages 56-60. ACM, 2018. URL:
  27. Mads Torgersen. The Expression Problem Revisited. In Martin Odersky, editor, Proceedings of the 18th European Conference on Object-Oriented Programming, volume 3086 of Lecture Notes in Computer Science, pages 123-143. Springer International Publishing, 2004. URL:
  28. Didier Verna. Revisiting the visitor: the "just do it" pattern. J. Univers. Comput. Sci., 16(2):246-270, 2010. URL:
  29. Philip Wadler. The expression problem, 1998. E-Mail to the Java Genericity Mailing List. URL:
  30. Yanlin Wang and Bruno C. d. S. Oliveira. The expression problem, trivially! In Lidia Fuentes, Don S. Batory, and Krzysztof Czarnecki, editors, Proceedings of the 15th International Conference on Modularity, MODULARITY 2016, Málaga, Spain, March 14 - 18, 2016, pages 37-41. ACM, 2016. URL:
  31. Matthias Zenger and Martin Odersky. Independently extensible solutions to the expression problem, 2004. URL:
  32. Haoyuan Zhang, Zewei Chu, Bruno C. d. S. Oliveira, and Tijs van der Storm. Scrap your boilerplate with object algebras. In Jonathan Aldrich and Patrick Eugster, editors, Proceedings of the 2015 ACM SIGPLAN International Conference on Object-Oriented Programming, Systems, Languages, and Applications, OOPSLA 2015, part of SPLASH 2015, Pittsburgh, PA, USA, October 25-30, 2015, pages 127-146. ACM, 2015. URL:
  33. Weixin Zhang and Bruno C. d. S. Oliveira. EVF: an extensible and expressive visitor framework for programming language reuse. In Peter Müller, editor, 31st European Conference on Object-Oriented Programming, ECOOP 2017, June 19-23, 2017, Barcelona, Spain, volume 74 of LIPIcs, pages 29:1-29:32. Schloss Dagstuhl - Leibniz-Zentrum für Informatik, 2017. URL:
  34. Weixin Zhang and Bruno C. d. S. Oliveira. CASTOR: Programming with extensible generative visitors. Sci. Comput. Program., 193:102449, 2020. URL:
  35. Yizhou Zhang and Andrew C. Myers. Familia: unifying interfaces, type classes, and family polymorphism. Proc. ACM Program. Lang., 1(OOPSLA):70:1-70:31, 2017. URL:
Questions / Remarks / Feedback

Feedback for Dagstuhl Publishing

Thanks for your feedback!

Feedback submitted

Could not send message

Please try again later or send an E-mail