Skip to main content
PreparationZone Logo
PreparationZone
Back to Java

Java · Hard · Pro

Visitor pattern in Java — when worth the boilerplate?

JavaDesign PatternsStaff
Model answerPreview

Visitor pattern

Visitor separates an operation from the object structure: each concrete element calls accept(visitor), and the visitor dispatches on type. It pays off when you have a stable hierarchy and many cross-cutting operations (pretty-print, validate, compile).