Visitor
Lets you add new operations to a set of object types without modifying those types, by moving the operation into a separate visitor object.
Why we need this / what value this brings
Lets a new operation over a fixed set of object types be added in one place, without touching every existing type to add a method to each.
When to use this
You have a stable set of object types but frequently need to add new operations that cut across all of them (e.g. export, tax calculation, validation).
How to use or implement this
Give each object type an accept(visitor) method that calls back into the visitor's type-specific method — heavier machinery than most backend code needs; a plain type-switch function is often simpler unless the type set is genuinely fixed and operations grow frequently.
Research questions
- Tax/fee calculation across different service/product types (payments module) is the shape this pattern targets — worth checking if it would actually simplify that code or just add indirection over a small, stable set of types.
- See Visitor Pattern's "When to use / when not to" section: the deciding question is whether the product/service type set churns more or less than the operations over it — check that before assuming Visitor is the right fit here.