The behavior of any real world application is dynamic. It changes based on various factors around it. The Visitor pattern helps an object accept the behavior of a visiting class. This makes it easy to plug and play the visitor with the element.
- Client: The Client class is a consumer of the classes of the visitor design pattern. It has access to the data structure objects and can instruct them to accept a Visitor to perform the appropriate processing.
- Visitor: This is an interface or an abstract class used to declare the visit operations for all the types of visitable classes.
- ConcreteVisitor: For each type of visitor all the visit methods, declared in abstract visitor, must be implemented. Each Visitor will be responsible for different operations.
- Visitable: This is an interface which declares the accept operation. This is the entry point which enables an object to be “visited” by the visitor object.
- ConcreteVisitable: These classes implement the Visitable interface or class and defines the accept operation. The visitor object is passed to this object using the accept operation.