Browse Java Design Patterns & Enterprise Application Architecture

Extensibility with Visitors

Understand the real extensibility trade-off in Java Visitor: new operations are easy, new element types are expensive.

Visitor improves one kind of extensibility and weakens another.

Easy To Extend

Adding a new operation is often easy:

  • add a new visitor type
  • keep element classes unchanged

Harder To Extend

Adding a new element type is often expensive:

  • update the visitor interface
  • update every concrete visitor

Review Rule

Choose Visitor only when operation growth is the dominant force and element-type churn is relatively low.

Revised on Thursday, April 23, 2026