[jdom-interest] Visitor (was: API Inertia)
Joseph Bowbeer
jozart at csi.com
Wed May 2 10:21:56 PDT 2001
Elliotte Rusty Harold writes
> Interesting. I'll have to read up on this pattern.
> Time to crack open Gamma again. One question below:
There's some more recent material at the link below (incl. reference to
GangOfFour)
http://www.ootips.org/visitor-pattern.html
> Why don't the visit methods return the values requested
> instead of void? Why the extra level of indirection?
I was wondering this myself as I was cutting and pasting my own example from
a previous message. It would make my example easier. Another question I
had was whether Visitor should be an interface and DefaultVisitor would be
the default implementation. These are all possible tweaks, I think.
> And one final note: this sort of stuff is not well-understood in the
> community we're targetting. Even simpler creational patterns like
> Factory Method and Abstract Factory throw many programmers
> for a loop. This is precisely why JDOM uses concrete classes
> rather than interfaces like DOM, and the added simplicity has
> been much appreciated.
If we're not targetting them then who is? I think of JDOM as a Java-centric
XML object model that is also a bit more intuitive than full-on DOM.
(That's why I use it, anyway.)
> I like taking advantage of design patterns in our implementation
> and package private API. I'm not so sure I want to require people
> using the API to be comfortable with patterns though.
A few simple patterns are good for everyone. We wouldn't be breaking any
new ground here, since the Java API itself is laced with patterns.
I admit that Visitor is the most complicated of the patterns -- probably
because it is the least direct. It's also "subject-oriented" rather than
object-oriented. One might say that Visitor is a fancy hook (hack?) for
attaching behavior to related objects. I also wouldn't want to make
understanding Visitor a requirement for all JDOM users.
--
Joe Bowbeer
More information about the jdom-interest
mailing list