OXFORD UNIVERSITY COMPUTING LABORATORY

The Visitor Pattern as a Reusable, Generic, Type-Safe Component

Bruno C. d. S. Oliveira, Meng Wang, and Jeremy Gibbons

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: no reflection or similar mechanisms are used. 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.

info

book title

Proceedings of the 23rd Annual ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA)

editor

Gregor Kiczales

journal

Proceedings of the 23rd Annual ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications

location

Nashville, Tennessee, US

month

October

year

2008

links

BibTeX

Link (pdf)

related pages

people

Random Image
Random Image
Random Image