Visitor Design Pattern

Intent

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.

Example

  • The Visitor Design Pattern is Java's attempt at resolving The Expression Problem.

  • Suppose a data structure that is a list containing either one element or is empty OneOrNone.

  • We could denote this with null or perhaps use the Visitor Design Pattern.