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.