language-icon Old Web
English
Sign In

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 the structures. It is one way to follow the open/closed principle.Represent an operation to be performed on elements of an object structure. Visitor lets you define a new operation without changing the classes of the elements on which it operates. 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 the structures. It is one way to follow the open/closed principle. In essence, the visitor allows adding new virtual functions to a family of classes, without modifying the classes. Instead, a visitor class is created 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. The Visitor design pattern is one of the twenty-three well-known GoF design patterns that describe how to solve recurring design problems to design flexible and reusable object-oriented software, that is, objects that are easier to implement, change, test, and reuse. What problems can the Visitor design pattern solve? When new operations are needed frequently and the object structure consists of many unrelated classes,it's inflexible to add new subclasses each time a new operation is requiredbecause ' distributing all these operations across the various node classes leads to a system that's hard to understand, maintain, and change.' What solution does the Visitor design pattern describe?

[ "Programming language", "visitor behavior", "Recreation ecology", "Visitor management" ]
Parent Topic
Child Topic
    No Parent Topic