Behavioral patterns
Visitor
Adds new operations to an object structure without modifying its classes.
Article
Visitor: new operations without changing classes
The Visitor pattern through a menu: dishes, drinks and sets stay untouched, while pricing, an allergen report or an export are separate visitor objects. Double dispatch, a comparison with pattern matching and code in five languages.
Related articles
- Composite – trees in which a leaf and a branch look the same
Composite lets you treat a single object and a whole group of objects in exactly the same way. A course curriculum example with modules and lessons in C#, TypeScript, Java, Go and Python.
Challenges
Around the topic
- The Visitor Pattern in Python (And Better Alternatives) video · youtube · ArjanCodes
- Odwiedzający / Visitor article · web · Refactoring.Guru
- Zero-Overhead Tree Processing with the Visitor Pattern article · web · lihaoyi.com
- The visitor pattern is essentially the same thing as Church encoding article · web · haskellforall.com
- Visitor article · web · Refactoring.Guru
- GopherCon 2025: Go with the (Work)Flow: AI-Driven Code Generation for Workflows - Samantha Coyle video · youtube · Gopher Academy
- Design Patterns – Iterators, Observers, and Chains, Oh My podcast · apple-podcasts · Coding Blocks