Role:
Represents an operation that acts on the elements of an object structure. It allows you to define new operations that act on these elements without changing the classes of each element.
UML Structure diagram:
Analytical:
The visitor mode encapsulates access to nodes as an abstract base class, generating new access patterns by deriving different classes. At the time of implementation, an interface function that accesses all the different nodes is declared in the visitor abstract base class, such as the Visitconcreateelementa function in the graph, it also creates a flaw in the visitor pattern--Adding a node to the interface function in the visitor. This allows all visitor and their derived classes to be recompiled, that is to say, a disadvantage of the visitor model is that it is difficult to add new nodes. In addition, it is also important to point out that the visitor model uses the so-called "double dispatch" technique, and takes the picture as an example, To access a node, you first need to produce an element derived class object, which is passed into a visitor class derived class object to invoke the corresponding accept function, that is to say, what kind of element is used for the visitor access, Need two times dynamic binding can be determined, the specific implementation can refer to the following implementation code in the Main.cpp part of how to invoke these classes.