The visitor pattern makes use of a visitor class, which changes the behavior of an element class.
This way, the algorithm choosing for execution can vary when the visitor varies.
This pattern comes under the behavioral pattern category.
As part of the pattern, the element object has to accept the visitor object so that the visitor object
handles the operation on the element object.
Let's have a look in the diagram.
And don't worry if this looks too complex, the visitor pattern is actually really easy to understand.
We can see that we got to interfaces, vehicle part and vehicle part visitor.
The vehicle part is implemented by parts of a vehicle and by the vehicle class as well.
This construct is used for building a new vehicle.
The visitor pattern interface is implemented by a single show, Visitor Concrete Glass, which outputs
the name of each vehicle component.
You can have as many vehicles as you want for any type of action.
Let's see how this looks like in the code.