[jdom-interest] Need of GOF Visitor Pattern implemantation in JDOM?

philip.nelson at omniresources.com philip.nelson at omniresources.com
Sat May 12 06:43:46 PDT 2001

> > But, now that you mention it, I still haven't figured out 
> what the benefit
> > of a
> > visitor pattern is over what to me is the more straightforward way:

> I would do it like this.
> Imagine org.jdom.Document
>      public aceept(Visitor aVisitor)  {
>         // ensurse call of adapter
>         aVisitor.vist(this); 
>        // visit attributs
>        Iterator attributeIterator = this.getAttributes.iterator();
>        while (attributeIterator.hasNext()) {
>              ((Attribute)attributeIterator.next()).accept(aVisitor);
>        }
>        // vist elements
>        // same as above applied to elements of document

While the idea of a Visitor generally appeals to me, I also think the real
benefit comes when you do something as suggested above: the traversal is
built into the jdom classes.  This is also the problem I have with it.
Should I do a depth first or a breadth first traversal?  Should I have a way
to stop traversing?  Should my traversal have a filter element?  Im sure
there are more variations but the answer is always the same, maybe.  If you
take the automatic traversal out and have the implementor of the visitor do
it (assuming that's possible and easy) then I agree with Alex, I would
rather traverse the document in a way that feels more natural.

More information about the jdom-interest mailing list