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:

    In verity ... we are the poor. This humanity we would claim for ourselves is the legacy, not only of the Enlightenment, but of the thousands and thousands of European peasants and poor townspeople who came here bringing their humanity and their sufferings with them. It is the absence of a stable upper class that is responsible for much of the vulgarity of the American scene. Should we blush before the visitor for this deficiency?
    Mary McCarthy (1912–1989)

    Every child has an inner timetable for growth—a pattern unique to him. . . . Growth is not steady, forward, upward progression. It is instead a switchback trail; three steps forward, two back, one around the bushes, and a few simply standing, before another forward leap.
    Dorothy Corkville Briggs (20th century)