Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
There are two key roles/components involved in the Visitor pattern, a visitor and an element that it visits. An element can be any object, but it is usually a node in a part-whole structure (see the Composite pattern in Chapter 13). A part-whole structure contains composite and leaf nodes or any other complex object structure. The element itself is not only limited to these kinds of structures. A visitor that knows every element in a complex structure can visit each of the element's nodes and perform any operations based on the element's attributes, properties, or operations. The class diagram in Figure15–1 illustrates their static relationships.
Figure 15–1. A class diagram illustrating the static structure of the Visitor pattern