The Visitor design pattern is a GOF (Gang of Four) pattern and can be used to define a new operation on your class sans the need of changing the existing code.

GOF patterns are classified into creational, behavioral, and structural categories depending on their purpose and usage.

The Visitor design pattern is behavioral pattern, and it’s a good choice if you would want to perform similar kinds of operations on objects of different types that are grouped inside a structure.The basic intent of the Visitor design pattern is to isolate an operation from an object structure on which it would operate.
It’s a good choice when you’re attempting to represent recursive structures like directory trees, XML structures, etc. You can use the Visitor Design Pattern to build a data model with limited internal functionality and then have a set of visitors that can operate on the data.
In essence, you can leverage this pattern to have a visitor type visit each of the elements of a data structure without the need of having an upfront knowledge on the structure.

This design pattern enables you to isolate the data model from the operations to be performed on the data.

This isolation helps you to add more and more functionalities (algorithms that can be used to perform operations on the data) over time.To read this article in full or to leave a comment, please click here

Leave a Reply