Visitor
From CSSEMediaWiki
Revision as of 21:12, 1 August 2008 by Tureiti Keith (Talk | contribs)
Introduction
The Visitor is a behavioural pattern. It allows the designer to define new operations on an object structure and its elements, without modifying the object structure itself.
Structure
The Visitor describes the relations between three distinct classes:
Class | Description |
ObjectStructure | Provides a visitor with access to its elements |
Element | Accepts visits. |
Visitor | Accesses an element to perform operations. |
Figure 1 graphically describes these Visitor pattern relationships.
Communication
The Visitor pattern allows a visitor object to access and perform operations on an element object. A summary of the Visitor pattern communications is given in Fig. 2. Here the following interactions are shown:
- Sequence 1 - The object aVisitor1 performs an operation on anElementA
- Sequence 2 - The object aVisitor2 performs an operation on anElementB
- Sequence 3 - The object aVisitor1 performs an operation on anElementA
- Sequence 4 - The object aVisitor2 performs an operation on anElementB