Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Well, you have to extend all your visitors.</p> <p>You have a caller, some elements that need to be visited, and an element - the visitor - that does the processing of the individual elements. Your goal is to keep the implementation of the elements and the caller fixed, and extend functionality via new visitors.</p> <p>Usually you have a lot of the concrete visitors. If you add a new type of element to be processed, you will need to change all the concrete visitors to take this into account.</p> <p>Why?</p> <p>well, imagine that the caller is "Factory", and you have the elements "Car" and "Bike".</p> <p>For operation "Paint" you have to have the methods</p> <pre><code>void process(Car c); // Paint a car void process(Bike b); // Paint a bike </code></pre> <p>Likewise for operations "Assemble", "Package", "Wash" etc.</p> <p>If you add an element "Scooter", all the operations have to be extended with a new method </p> <pre><code>void process(Scooter s); // Handle a Scooter </code></pre> <p>This is a bit of work. Also you may hit the isse where the element you add is so different from the others that you canøt easily fit them to the operations. </p> <p>Wikipedia (http://en.wikipedia.org/wiki/Visitor_pattern) says </p> <blockquote> <p>In essence, the visitor allows one to add new virtual functions to a family of classes without modifying the classes themselves; instead, one creates a visitor class that implements all of the appropriate specializations of the virtual function. The visitor takes the instance reference as input, and implements the goal through double dispatch.</p> </blockquote> <p>That's a pretty abstract way of saying what I try to say above. Usually you'd add these methods to the elements, but if you can't you have to add the methods to somethign else, and pass that along to do the processing. This is a bit of extra work, but may be worth it, if the situation merits it.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload