1.Topics‎ > ‎Architecture‎ > ‎Patterns‎ > ‎a.Design Patterns‎ > ‎D.Behavioral Patterns‎ > ‎

Visitor Pattern

  1. Summary
    1. This pattern allows different operations to be performed on the elements in a hierarchical object structure (composite object structure). 
    2. Visitor lets you define a new operation without changing the classes of the elements on which it operates.
  2. Examples
    1. Tree and Graph traversal algorithms.
  3. Overview Tutorial
    1. http://sourcemaking.com/design_patterns
    2. http://www.oodesign.com/visitor-pattern.html
  4. When to Use
    1. Similar operations have to be performed on objects of different types grouped in a structure (a collection or a more complex structure).
    2. There are many distinct and unrelated operations needed to be performed. Visitor pattern allows us to create a separate visitor concrete class for each type of operation and to separate this operation implementation from the objects structure.
    3. The object structure is not likely to be changed but is very probable to have new operations which have to be added.
    4. Since the pattern separates the visitor (representing operations, algorithms, behaviors) from the object structure it's very easy to add new visitors as long as the structure remains unchanged.