[jdom-interest] RE: jdom-interest digest, Vol 1 #573 - 53 msgs

Trimmer, Todd todd.trimmer at trizetto.com
Wed May 2 13:36:32 PDT 2001


Write your walker class that has to deal with all the various JDOM classes
(Element, CDATA, Comment, etc.). Now rewrite that same class that only has
to deal with a base Node class. Which was easier?

With Node, I can have an Iterator feed Nodes to a Visitor that only cares
about Nodes as Nodes, that is, it never has to downcast. This way I never
have to pay for downcasting if I never use it. Now let's say I have other
Visitors that DO care about specific type. I can use the exact same Iterator
and place all the casting code in the Visitor. Now, I only pay if I need to.


Todd Trimmer

-----Original Message-----

Message: 51
From: "Paul Philion" <philion at acmerocket.com>
To: <jdom-interest at jdom.org>
Subject: RE: [jdom-interest] Design Patterns - Visitor
Date: Wed, 2 May 2001 13:38:44 -0400

Frank -

I beg to differ: There are several ways to skin the Visitor, and
(personally) I try to stay away from the method you describe below.

I don't want my visited objects to implement any special interface, and I
use an implementation of the Visitor that does not require it. In my
Visitor, there are three significant actors:

- The object structure being "visited".
- A walker class that traverses the objects being visited, based on the
object structure.
- A visitor class them implements a "visit" method.

Given this structure, the walker can vary independently of the visitor,
allowing the structure to be traversed in a number of different ways, and
possibly implementing some level of filtering. The visitor class is
responsible for actually doing something with the visited object.

- Paul Philion



More information about the jdom-interest mailing list