Browse Java Design Patterns & Enterprise Application Architecture

Visitor Pattern

Use the Visitor pattern in Java when operations should vary more often than the object structure they operate on.

Visitor is one of the more specialized behavioral patterns. It is most useful when:

  • the object structure is relatively stable
  • many different operations must be applied to it
  • you want to keep those operations out of the element classes

It is commonly discussed with ASTs, document models, and other structured object graphs. It is usually a poor fit when element types change frequently.

In this section

Revised on Thursday, April 23, 2026