ABSTRACT
The VISITOR design pattern shows how to separate the structure of an object hierarchy from the behaviour of traversals over that hierarchy. The pattern is very flexible; this very flexibility makes it difficult to capture the pattern as anything more formal than prose, pictures and prototypes.
We show how to capture the essence of the VISITOR pattern as a reusable software library, by using advanced type system features appearing in modern object-oriented languages such as Scala. We preserve type-safety statically and modularly: no reflection or similar mechanisms are used and modules can be independently compiled. The library is generic, in two senses: not only is it parametrised by both the return type and the shape of the object hierarchy, but also it allows a number of implementation choices (internal versus external control, imperative versus functional behaviour, orthogonal aspects such as tracing and memoisation) to be specified by parameters rather than fixed in early design decisions. Finally, we propose a generalised datatype-like notation,on top of our visitor library: this provides a convenient functional decomposition style in object-oriented languages.
- Jonathan Aldrich. Open modules: Modular reasoning about advice. In LNCS 3586: European Conference on Object-Oriented Programming, pages 144--168, 2005. Google Scholar
- Karine Arnout. Pattern Componentization. PhD thesis, Swiss Institute of Technology, March 2004.Google Scholar
- Richard Bird and Lambert Meertens. Nested datatypes. In J. Jeuring, editor, LNCS 1422: Mathematics of Program Construction, pages 52--67, 1998. Google Scholar
Digital Library
- Richard S. Bird and Oege De Moor. Algebra of Programming. Prentice Hall, 1997. Google Scholar
Digital Library
- Corrado Bohm and Alesssandro Berarducci. Automatic synthesis of typed lambda-programs on term algebras. Theoretical Computer Science, 39(2-3):135--153, August 1985.Google Scholar
Cross Ref
- Peter Buchlovsky and Hayo Thielecke. A type-theoretic reconstruction of the Visitor pattern. Electronic Notes in Theoretical Computer Science, 155, 2005. Mathematical Foundations of Programming Semantics. Google Scholar
Digital Library
- Bryan Chadwick and Karl Lieberherr. Functional Adaptive Programming with DemeterF. Technical Report NU-CCIS-08-March19, Northeastern University, Boston, March 2008.Google Scholar
- Bryan Chadwick, Therapon Skotiniotis, and Karl Lieberherr. Functional Visitors Revisited. Technical Report NU-CCIS-06-03, Northeastern University, Boston, May 2006.Google Scholar
- Craig Chambers and Gary T. Leavens. Typechecking and modules for multimethods. ACM Transactions on Programming Languages and Systems, 17(6):805--843, November 1995. Google Scholar
Digital Library
- Alonzo Church. An unsolvable problem of elementary number theory. American Journal of Mathematics, 58:345--363, 1936.Google Scholar
- Curtis Clifton, Gary T. Leavens, Craig Chambers, and Todd Millstein. MultiJava: Modular open classes and symmetric multiple dispatch for Java. In Object-Oriented Programming, Systems, Languages, and Applications, pages 130--145, 2000. Google Scholar
- Vincent Cremet and Philippe Altherr. Adding type constructor parameterization to Java. Journal of Object Technology, 7(5):25--65, June 2008. Special issue on ECOOP 2007 Workshop on Formal Techniques for Java-like Programs.Google Scholar
Cross Ref
- Antonio Cunei and Jan Vitek. PolyD: a flexible dispatching framework. In Object Oriented Programming, Systems, Languages, and Applications, pages 487--503, New York, NY, USA, 2005. ACM. doi: http://doi.acm.org/10.1145/ 1103845.1094849. Google Scholar
- Michael Ernst, Craig Kaplan, and Craig Chambers. Predicate dispatching: A unified theory of dispatch. In European Conference on Object-Oriented Programming, pages 186--211, London, UK, 1998. Springer-Verlag. Google Scholar
Digital Library
- Remi Forax, Etienne Duris, and Gilles Roussel. Reflection-based implementation of Java extensions: The double-dispatch use-case. In ACM Symposium on Applied Computing, pages 1409--1413, 2005. Google Scholar
Digital Library
- Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides. Design Patterns: Elements of Reusable Object-Oriented Software. Addison-Wesley, 1995. Google Scholar
Digital Library
- Jeremy Gibbons. Patterns in datatype-generic programming. In J. Striegnitz, editor, Declarative Programming in the Context of Object-Oriented Languages, Uppsala, 2003.Google Scholar
- Jeremy Gibbons. Design patterns as higher-order datatype-generic programs. In ACM Workshop on Generic Programming, pages 1--12, 2006. Google Scholar
Digital Library
- Jeremy Gibbons and Bruno Oliveira. The essence of the Iterator pattern. Journal of Functional Programming, 2008. Google Scholar
Digital Library
- Jean-Yves Girard, Paul Taylor, and Yves Lafont. Proofs and types. Cambridge University Press, 1989. Google Scholar
Digital Library
- Christian Grothoff. Walkabout revisited: The Runabout. In LNCS 2743: European Conference on Object-Oriented Programming, pages 103--125, 2003.Google Scholar
- Stephan Gudmundson and Gregor Kiczales. Addressing practical software development issues in AspectJ with a pointcut interface. In ECOOP 2001 Workshop on Advanced Separation of Concerns, 2001.Google Scholar
- Jan Hannemann and Gregor Kiczales. Design pattern implementation in Java and AspectJ. SIGPLAN Not., 37(11): 161--173, 2002. Google Scholar
Digital Library
- Robert Harper and Mark Lillibridge. A type-theoretic approach to higher-order modules with sharing. In Principles of Programming Languages, pages 123--137, 1994. Google Scholar
Digital Library
- Gregor Kiczales and Mira Mezini. Aspect-oriented programming and modular reasoning. In ACM: International Conference on Software engineering, pages 49--58, 2005. Google Scholar
Digital Library
- Gregor Kiczales, John Lamping, Anurag Menhdhekar, Chris Maeda, Cristina Lopes, Jean-Marc Loingtier, and John Irwin. Aspect-oriented programming. In Mehmet Aks 'it and Satoshi Matsuoka, editors, LNCS 1241: European Conference on Object-Oriented Programming, pages 220--242, 1997.Google Scholar
- Xavier Leroy. Manifest types, modules, and separate compilation. In Principles of Programming Languages, pages 109--122, 1994. Google Scholar
Digital Library
- Doug McIlroy. Mass produced software components. In Naur and Randell (1969), pages 138--155.Google Scholar
- Lambert Meertens. Paramorphisms. Formal Aspects of Computing, 4(5):413--425, 1992.Google Scholar
Cross Ref
- Erik Meijer and Graham Hutton. Bananas in space: Extending fold and unfold to exponential types. In Functional Programming Languages and Computer Architecture, pages 324--333, 1995. Google Scholar
Digital Library
- Bertrand Meyer. Object-Oriented Software Construction. Upper Saddle River, N.J., Prentice Hall, 2nd edition, 1997. Google Scholar
Digital Library
- Bertrand Meyer and Karine Arnout. Componentization: The Visitor example. Computer, 39(7):23--30, 2006. Google Scholar
Digital Library
- Donald Michie. Memo functions and machine learning. Nature, 218:19--22, 1968.Google Scholar
Cross Ref
- Adriaan Moors, Frank Piessens, and Martin Odersky. Towards equal rights for higher-kinded types. In 6th International Workshop on Multiparadigm Programming with Object-Oriented Languages, 2007.Google Scholar
- Peter Naur and Brian Randell, editors. Software Engineering: Report of a Conference Sponsored by the NATO Science Committee, Garmisch, Germany, 7-11 Oct. 1968. 1969.Google Scholar
- Peter Norvig. Design patterns in dynamic programming. In Object World 96, May 1996.Google Scholar
- Martin Odersky. An Overview of the Scala programming language (second edition). Technical Report IC/2006/001, EPFL Lausanne, Switzerland, 2006.Google Scholar
- Martin Odersky and Matthias Zenger. Independently extensible solutions to the expression problem. In Proceedings of Foundations of Object-Oriented Languages 12, January 2005a. http://homepages.inf.ed.ac.uk/wadler/fool.Google Scholar
- Martin Odersky and Matthias Zenger. Scalable component abstractions. In Object Oriented Programming, Systems, Languages, and Applications, pages 41--57, 2005b. Google Scholar
- Bruno C.d.S. Oliveira. Genericity, Extensibility and Type-Safety in the Visitor Pattern. PhD thesis, University of Oxford, 2007.Google Scholar
- Doug Orleans and Karl Lieberherr. DJ: Dynamic adaptive programming in Java. In Reflection 2001: Meta-level Architectures and Separation of Crosscutting Concerns, Kyoto, Japan, September 2001. Springer Verlag. Google Scholar
Digital Library
- Jens Palsberg and C. Barry Jay. The essence of the Visitor pattern. In Computer Software and Applications, pages 9--15, 1998. Google Scholar
Digital Library
- Michel Parigot. Recursive programming with proofs. Theoretical Computer Science, 94(2):335--356, 1992. Google Scholar
Digital Library
- Simon Peyton Jones, editor. Haskell 98 Language and Libraries - The Revised Report. Cambridge University Press, Cambridge, England, 2003.Google Scholar
- Cuno Pfister and Clemens Szyperski. Why objects are not enough. In International Component Users Conference, 1996. Google Scholar
Digital Library
- ZdzisBaw SpBawski and PaweB Urzyczyn. Type fixpoints: Iteration vs. recursion. In International Conference on Functional Programming, pages 102--113, 1999. Google Scholar
Digital Library
- Clemens Szyperski. Independently extensible systems - software engineering potential and challenges. In 19th Australian Computer Science Conference, 1996.Google Scholar
- Peri Tarr, Harold Ossher, William Harrison, and Stanley Sutton, Jr. N degrees of separation: Multi-dimensional separation of concerns. In International Conference on Software Engineering, pages 107--119, 1999. Google Scholar
Digital Library
- Thomas VanDrunen and Jens Palsberg. Visitor-oriented programming. In Proceedings of FOOL-11, the 11th ACM SIGPLAN International Workshop on Foundations of Object-Oriented Languages, New York, NY, USA, January 2004. ACM Press.Google Scholar
- Joost Visser. Visitor combination and traversal control. In Object Oriented Programming, Systems, Languages, and Applications, pages 270--282. ACM, 2001. Google Scholar
Digital Library
Index Terms
The visitor pattern as a reusable, generic, type-safe component
Recommendations
The visitor pattern as a reusable, generic, type-safe component
The VISITOR design pattern shows how to separate the structure of an object hierarchy from the behaviour of traversals over that hierarchy. The pattern is very flexible; this very flexibility makes it difficult to capture the pattern as anything more ...
A survey report of enhancements to the visitor software designpattern
The Visitor pattern is a behavioral software design pattern where different objects represent an operation to be performed on elements of an object structure. Despite the benefits of the Visitor pattern, its rigid structure has limitations. Owing to the ...
A pattern for almost compositional functions
Proceedings of the 2006 ICFP conferenceThis paper introduces a pattern for almost compositional functions over recursive data types, and over families of mutually recursive data types. Here "almost compositional" means that for a number of the constructors in the type(s), the result of the ...







Comments