public interface DomElementVisitor
DomElement
interface has methods DomElement.accept(DomElementVisitor)
and DomElement.acceptChildren(DomElementVisitor)
taking this visitor as a parameter.
DomElementVisitor has only one method: visitDomElement(DomElement)
.
Where is the Visitor pattern? Where are all those methods with names like visitT(T)
that
are usually found in it? There are no such methods, because the actual interfaces (T
's)
aren't known to anyone except you. But when you instantiate the DomElementVisitor
interface, you may add your own visitT()
methods and they will be called! You may
even name them just visit()
, specify the type of the parameter and everything will be
fine.
For example, if you have two DOM element classes - Foo
and Bar
- your visitor
may look like this:
class MyVisitor implements DomElementVisitor { void visitDomElement(DomElement element) {} void visitFoo(Foo foo) {} void visitBar(Bar bar) {} }
Modifier and Type | Method and Description |
---|---|
void |
visitDomElement(DomElement element) |
void visitDomElement(DomElement element)