Abstract classes, Interfaces, and Patterns
- slide 37 : 37
Visitors - Pros and Cons
There are both advantages and disadvantages of
Visitor
Integer Sequence Composite
Consequences of using a
Visitor
A new kind of traversal can be added without affecting the classes of the
Composite
A
Visitor
encapsulates all methods related to a particular traversal
State related to a traversal can - in a natural way - be represented in the
Visitor
If a new class is added to the
Composite
all
Visitor
classes are affected
The indirect recursion that involves
Accept
and the
Visit
methods is more complex than the direct recursion in the natural object-oriented solution
Visitor
is frequently used for processing of abstract syntax trees in compiler construction tools