[jdom-interest] API Inertia

Joseph Bowbeer jozart at csi.com
Wed May 2 03:13:17 PDT 2001


> So, things like the common interface/base class thing. ...

A Node interface that extends Visitable was proposed here:

http://lists.denveronline.net/lists/jdom-interest/2000-November/003610.html

A clip from the original post follows.  What if anything beyond Visitable
should a Node implement?

-----

Making all the JDOM classes implement Visitable and providing a Visitor
baseclass for the users to extend would give users a mechanism for
implementing custom traversals, as well as a mechanism for attaching
additional behavior to the JDOM classes.

I'm refering to the Visitor pattern by the Gang Of Four.  There's a good
description plus links to more resources here:

    http://www.ootips.org/visitor-pattern.html

Details:

Given a Visitable interface defined by JDOM:

    interface Visitable {
        void accept(Visitor visitor);
    }

Each concrete object in a document would implement Visitable, for
example:

    class Element implements Visitable {
        // ...
        public void accept(Visitor visitor) {
            visitor.visitElement(this);
        }
    }

JDOM would also define an abstract base class for visitors:

    abstract class Visitor {
        public void visitDocument(Document document);
        public void visitElement(Element element);
        public void visitAttribute(Attribute attribute);
        // ...
    }

--
Joe Bowbeer





More information about the jdom-interest mailing list