Guiding visitors: separating navigation from computation

Martin Bravenboer, Eelco Visser. Guiding visitors: separating navigation from computation. Technical Report UU-CS-2001-42, Department of Information and Computing Sciences, Utrecht University, 2001.

Abstract

Traversals over the object structure are widely used in object-oriented programming, in particular in language processing applications. The vis- itor pattern separates computation from traversal by specifying the com- putations that should be performed at each object in a separate visitor class. This makes the implementation of di erent computations reusing the same traversal scheme possible. However, navigation through the ob- ject structure is xed in the accept methods implemented by the objects that are traversed. This makes it dicult to use other navigation orders. In this paper, we introduce the Guide pattern that describes the sep- aration of navigation from computation and object structure using a double-dispatching iterator. The pattern makes it possible to implement a whole range of navigation schemes for an object-structure. Using a self- dispatching approach based on re ective method lookup such navigation schemes can be made reusable for whole classes of object-structures (im- plementing a common interface). The eciency of this approach is pro- vided by caching method lookups. We extend the approach to generic nav- igation through arbitrary object-structures using re ective eld lookup. This results in a generalization of the Walkabout class of Palsberg and Jay with a huge performance improvement in Java, making the Walka- bout usable in practice.