October 2018
Intermediate to advanced
370 pages
9h 15m
English
The visitor pattern allows us to add new operations to an existing object without modifying it. This pattern is a way to extend functionality and follow the open/closed principle. It's better to try to understand this pattern using a particular example.
The following diagram represents the example that we will touch upon, as follows:

The preceding diagram contains the CarElement interface that is implemented by the Body and Engine classes. The CarElementDriverVisitor class implements the CarElementVisitor interface, which contains an instance of the CarElementVisitor type.
Let's define the CarElement interface:
interface CarElement ...
Read now
Unlock full access