Visitor

Add operations over a fixed structure via double dispatch

Visitor lets you add new operations to a set of object types without modifying them, by having each element accept(visitor) and call back visitor.visit_X(self). That two-hop callback is double dispatch โ€” the method that runs depends on both the element type and the visitor type.

Be honest: Visitor is clunky in dynamic languages. In Python you'd usually just write a function that does a match/isinstance on the item type โ€” no accept methods, no double dispatch. Learn it, but reach for pattern matching first.