Lecture overview -- Keyboard shortcut: 'u'  Previous page: A Visitor example: IntSequence -- Keyboard shortcut: 'p'    Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Textbook -- Keyboard shortcut: 'v'  Help page about these notes  Alphabetic index  Course home  Page 37 : 37
Object-oriented Programming in C#
Abstract classes, Interfaces, and Patterns
Visitors - Pros and Cons

There are both advantages and disadvantages of Visitor

 

  • 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