• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/5

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

5 Cards in this Set

  • Front
  • Back

Intent

•Represent an operation to beperformed on the elements of an object structure. Visitor lets you define a new operationwithout changing the classes of the elements on which it operates.

Structure

Consequences

•Makes adding new operations easy. Visitors make it easy to add operations that depend on the components ofcomplex objects. You can define a newoperation over an object structure simply by adding a new visitor.




•Gathers related operations and separatesunrelated ones. Related behavior isn’t spread over theclasses that define the object structure; it’s localized in a visitor.




•Permits visiting across class hierarchies. In contrast to the Iterator pattern, visitors can visit objects thatdon’t have a common parent class; i.e., all objects in the structure are notrequired to have the same type.

Double dispatch vs Single dispatch

singledispatch - Theactual method invoked depends on the method signature and the type of thereceiver object.




doubledispatch - Theactual method invoked depends on the method signature and the types of tworeceivers. accept() is a double-dispatch operation

Who is responsible for traversing theobject structure?

•The responsibility for traversalcan be in any of three places.




–theobject structure (e.g., by having each accept()operation traverse the elements children and call accept()on each of them recursively)




–thevisitor (e.g., to implement a particularly complex traversal that depends onthe results of operations on the object structure)




–ina separate iterator object