Skip to content

99. Visitor Pattern

Ercan Polat edited this page Jan 19, 2019 · 1 revision

11.Visitor

Represent an operation to be performed on the elements of an object structure. Visitor lets you define a new operation without changing the classes of the elements on which it operates.

Use the Visitor pattern when…

  • You have a class hierarchy that is effectively sealed.
  • There are many distinct operations to perform on it.
  • The operations are orthogonal to the core purpose of the types in the hierarchy.
  • You need the flexibility to define new operations over time.

Computer World Example

This pattern is useful when public APIs need to support plug-in operations. Clients can then perform their intended operations on a class (with the visiting class) without modifying the source.

Clone this wiki locally