skills/skills.volces.com/visitor-pattern-implementor

visitor-pattern-implementor

Installation
SKILL.md

Visitor Pattern Implementor

When to Use

You have an object structure (a hierarchy of related element classes) and need to perform operations on those objects without modifying the element classes themselves. This skill applies when:

  • The element class hierarchy is stable — it rarely gains new subclasses, but you frequently need to add new operations over the structure. This is the stability decision rule: if the hierarchy changes often, do not use Visitor.
  • Many distinct and unrelated operations need to be performed on the same object structure, and you want to avoid polluting element classes with those operations.
  • State must accumulate across a traversal — the operation builds up a result by visiting multiple elements in sequence (e.g., collecting all misspellings, computing a total price).
  • The object structure is shared across multiple applications and you want each application to add only its own operations, not affect shared element code.

The go/no-go decision before proceeding:

Element hierarchy stability Operation change frequency Verdict
Stable (rare new elements) High (many new operations) Use Visitor
Unstable (frequent new elements) Any Avoid Visitor — each new element requires adding an abstract Visit method to every Visitor and implementing it in every ConcreteVisitor
Stable Low (1-2 operations total) Consider simpler approach — Visitor may be over-engineering
Installs
3
First Seen
Apr 24, 2026
visitor-pattern-implementor from skills.volces.com