Visitor Pattern

Visitor Pattern

In object-oriented programming and software engineering, the visitor design pattern is a way of separating an algorithm from an object structure on which it operates. A practical result of this separation is the ability to add new operations to existing object structures without modifying those structures. It is one way to easily follow the open/closed principle.

In essence, the visitor allows one to add new virtual functions to a family of classes without modifying the classes themselves; instead, one creates a visitor class that implements all of the appropriate specializations of the virtual function. The visitor takes the instance reference as input, and implements the goal through double dispatch.

Read more about Visitor Pattern:  Motivation, Details, Java Example, State, Related Design Patterns

Famous quotes containing the words visitor and/or pattern:

    “Beauty is ever to the lonely mind
    A shadow fleeting; she is never plain.
    She is a visitor who leaves behind
    The gift of grief, the souvenir of pain.”
    —Robert Nathan (1894–1985)

    “Why it was that upon this beautiful feminine tissue, sensitive as gossamer, and practically blank as snow as yet, there should have been traced such a coarse pattern as it was doomed to receive; why so often the coarse appropriates the finer thus, the wrong man the woman, the wrong women the man, many years of analytical philosophy have failed to explain to our sense of order.”
    —Thomas Hardy (1840–1928)