Interface Visitable

public interface Visitable

Interface to be implemented by objects supporting the Visitor design pattern.

Rod Johnson

Method Summary
 void acceptVisitor(Visitor v, int depth)
          Accept the given visitor.

Method Detail


public void acceptVisitor(Visitor v,
                          int depth)
Accept the given visitor.
There are two cases:
  1. The host (this Visitable object) is a composite element, with subnodes: The host is responsible for calling the visitor's enterComposite() method, calling the acceptVisitor(Visitor) method on any subnodes implementing this interface, and calling the visitor's exitComposite() method to end the visit. Note that the Visitor can prevent the evaluation of subnodes by returning false in enterComposite(), in which case this object should call acceptVisitor() on itself instead of child nodes, and ignore the call to exitComposite().
  2. The element is a leaf, with no subnodes: The element must call the Visitor's visit() method on itself
v - Visitor
depth - current depth of traversal, starting at 0

Rod Johnson and Spring contributors 2001-2003.