The Visitor Design Pattern is a behavioural pattern.
The Visitor Design Pattern allows one or more operation to be applied to a set of object at runtime and decoupling the operations from the base object structure.
Visitor Design Pattern examples
Scenario A in Drupal
Scenario A in PHP
If we need to add more business logics into the view method, then we have to modify the base class 'Node' which this is not a good practice.
By using Visitor Design Pattern, we can easier to add unlimited logics into the 'view' method without changing the base class.
When to use Visitor Design Pattern?
The Visitor Design Pattern is valuable if you have to perform a number of unrelated operations across the classes. It will avoid to add/modify codes throughtout your base object structure.
When objects containing algorithms to be applied to an object in a standard way are required, using the Visitor Design Pattern is best practice.
What differences between Visitor Design Pattern and others?
The Observer Pattern and Visitor Pattern have very similar concepts. A Observer Pattern will notify when something happens. A Visitor Pattern not only respond to events, and it also do somethings to extend the behavior of the base object. A Visitor Pattern is trying to separeate a complexity algorithm from the base object. A Observer Pattern is trying to notify to do somethings that maybe not related to the base object.