Visitor

Advanced · 15 min read · Low-Level Design, Behavioral Patterns

Adding operations to a stable class hierarchy via double dispatch.

This is an Advanced lesson, part of Premium. What it covers:

  • The idea in plain words
  • The problem
  • The solution: double dispatch
  • The trade-off: the expression problem
  • Modern Java alternative: sealed types + pattern matching
  • Where you've seen it
  • Pros and cons
  • Related patterns
  • Interview questions
  • Further reading

Previous: Memento · Next: Concurrency for LLD