Java · Hard · Pro
Visitor pattern in Java — when worth the boilerplate?
JavaDesign PatternsStaff
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).