Visitor Pattern

Noun · Development

Definitions

  1. A behavioral design pattern that separates an algorithm from the object structure it operates on by defining a visitor interface with a visit method for each element type, and having elements accept the visitor via double dispatch. Commonly used to traverse and process ASTs, IR nodes, and other recursive data structures.

    In plain English: A design approach where you add new operations to a set of objects by writing a separate 'visitor' class rather than modifying the objects themselves.

    Example: "The type checker, code generator, and pretty printer are all visitors over the same AST — adding a new pass doesn't touch the node classes."

Related Terms