10/09/2004

Visitor thoughts

Riley white gives an excellent visitor example and explanation.

My 2 cents are
  • I prefer foreign method to visitor pattern. Foreign method can traverse Subject's hierarchy with out accept method in subject. In reily white's example I would have some thing like

    class CheckoutImpl extends Checkout{
       void checkout(ShoppintCart cart) {
         Collection items = cart.getItems();
         // traverse and add all items.
       }
    }

    Only advantage of Visitor is it's accept method can encapsulate traversing items in a Subject. In Most cases it tends to be very simple traversal.

    Use visitor only when there is a need to do special traversal. For example when traversing a closet an employee need to sort only items under $3.00 or need to remove expired items. Then Subject's accept method becomes

    void accept(Visitor v, Condition c){
       Collection = getItemsSatisfyingCondition(c);
       doNormalAccept...
    }



  • Java (my language choice) determines overloaded resolution at compile time, visitor need to have explicit visit methods for each sub type of Subject and an instance of checking method to resolve and call explicitly typed methods. Resolving these conditional type checks is some sort of ugly code.
    Changes in Subject hierarchy causes changing all visitor implementations.

    Beware of these problems and (as advised by GoF) use visitor only when subject hierarchy is stable(rarely/never changes).



2 Comments:

At 11/23/2010, Anonymous generic cialis said...

In principle, a good happen, support the views of the author

 
At 12/04/2010, Anonymous fuck stories said...

Johns legs pinned mine, spreadoutwards revealing my pussy to the world. Leegates had lowered his hands to the nipples on her feelie star titswhen directed, her originals had been the same size, but had sagged like softloaves of Italian bread the thick nipples on the big areolae, however,were original equipment, but his first utterance as she settled onto him was, Jeezus.
young first time stories
sexy blow job stories
first time dog sex stories
sex stories young teen incest
adult stories young incest
Johns legs pinned mine, spreadoutwards revealing my pussy to the world. Leegates had lowered his hands to the nipples on her feelie star titswhen directed, her originals had been the same size, but had sagged like softloaves of Italian bread the thick nipples on the big areolae, however,were original equipment, but his first utterance as she settled onto him was, Jeezus.

 

Post a Comment

<< Home