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 (19121989)
“A two-week-old infant cries an average of one and a half hours every day. This increases to approximately three hours per day when the child is about six weeks old. By the time children are twelve weeks old, their daily crying has decreased dramatically and averages less than one hour. This same basic pattern of crying is present among children from a wide range of cultures throughout the world. It appears to be wired into the nervous system of our species.”
—Lawrence Kutner (20th century)