The visitor pattern as a reusable, generic, type-safe component

Bruno Oliveira, Meng Wang, Jeremy Gibbons

Research output: Chapter in Book/Report/Conference proceedingConference Contribution (Conference Proceeding)

20 Citations (Scopus)
6 Downloads (Pure)

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.

Original languageEnglish
Title of host publicationOOPSLA '08 Proceedings of the 23rd ACM SIGPLAN conference on Object-oriented programming systems languages and applications
PublisherAssociation for Computing Machinery (ACM)
Pages439
Number of pages456
DOIs
Publication statusPublished - 2008

Keywords

  • algebraic datatypes
  • design patterns
  • program extensibility
  • software components
  • traversal
  • visitor pattern

Fingerprint Dive into the research topics of 'The visitor pattern as a reusable, generic, type-safe component'. Together they form a unique fingerprint.

Cite this