![]() Both classes, CarElement and CarElementVisitor act as interfaces. The object hierarchy is pretty stable, but the operation hierarchy may support new operations. The object hierarchy ( CarElement) and the operation hierarchy ( CarElementVisitor). The Visitor Pattern has two type of hierarchies. Let me use it to explain the structure and the dynamic behavior of the Visitor Pattern. This picture gives a very good impression of the Visitor Pattern. The following picture from the Visitor Pattern on Wikipedia provides more insight.īy Fuhrmanator - Using the PlantUML software, CC BY-SA 3.0, Defines the accept operation that takes a visitor as an argument.Defines the visit operation on the object structure.Operations should be performed on an object hierarchy. ![]() ![]() Enables to define new operations without changing the object hierarchy.Encapsulates an operation executed on an object hierarchy in an object.Let me first write about the Visitor Pattern before I discuss single dispatch and double dispatch. Of course, the complicatedness of the Visitor Pattern is mainly due to the fact that double dispatch is not natively supported in C++, such as in Eiffel. Double dispatch describes the process of choosing the member function based on the object and the function arguments. First, for its complicatedness, and second, for a technique called double dispatch. The Visitor Pattern from the book " Design Patterns: Elements of Reusable Object-Oriented Software" is legendary for two reasons. The Visitor Pattern encapsulates an operation executed on an object hierarchy as an object and enables it to define new operations without changing the object hierarchy.
0 Comments
Leave a Reply. |