gof-visitor
Installation
SKILL.md
One-line summary
Represent an operation to be performed on the elements of a stable object structure — letting you add new operations to the structure without modifying its element classes.
When to use this skill
- A stable hierarchy of types (AST nodes, file-system entries, document elements) needs new operations added over time and you don't want to keep touching each element class.
- You need to perform different operations on the same hierarchy: a pretty-printer, a type-checker, a JSON serializer, a metrics-collector. Each is a separate Visitor.
- The classical GoF "double dispatch" use case — picking which method to call based on two dynamic types (the element type and the operation type).
When NOT to use this skill
- The hierarchy is itself unstable — every new element type forces every Visitor to be updated. Visitor trades "adding operations is cheap" for "adding element types is expensive".
- The language already gives you exhaustive pattern matching (Kotlin
whenoversealedtypes, Rustmatch, Scala pattern matching). In those languages, you can add an operation as a function with an exhaustivewhen— without subclassing each element. - You only have one operation to add and there's no reason to expect more. A method on the element is simpler.
Core content
Two parallel pieces: