[jdom-interest] API Inertia
Elliotte Rusty Harold
elharo at metalab.unc.edu
Wed May 2 06:31:49 PDT 2001
At 3:25 AM -0700 5/2/01, Joseph Bowbeer wrote:
>PS - Here's an attempt to show a simple Visitor example:
>
Interesting. I'll have to read up on this pattern. Time to crack open
Gamma again. One question below:
>For example, the XPath getValue method for Attribute, Element, etc.
>could be implemented using a XPathValueVisitor.
>
>This would require that every object in a document implement Visitable.
>
> interface Visitable {
> void accept(Visitor visitor);
> }
>
>The XPathValueVisitor computes the value appropriate for the particular
>visitable instance:
>
> class XPathValueVisitor extends Visitor {
> Object value;
> void visitElement(Element element) {
> value = element.whatever();
> }
> void visitAttribute(Attribute attribute) {
> value = attribute.whatever();
> }
> // ...etc...
> }
>
Why don't the visit methods return the values requested instead of
void? Why the extra level of indirection?
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.
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.
--
+-----------------------+------------------------+-------------------+
| Elliotte Rusty Harold | elharo at metalab.unc.edu | Writer/Programmer |
+-----------------------+------------------------+-------------------+
| The XML Bible (IDG Books, 1999) |
| http://metalab.unc.edu/xml/books/bible/ |
| http://www.amazon.com/exec/obidos/ISBN=0764532367/cafeaulaitA/ |
+----------------------------------+---------------------------------+
| Read Cafe au Lait for Java News: http://metalab.unc.edu/javafaq/ |
| Read Cafe con Leche for XML News: http://metalab.unc.edu/xml/ |
+----------------------------------+---------------------------------+
More information about the jdom-interest
mailing list