org.perfectjpattern.core.behavioral.visitor
Class AbstractVisitor<E>

java.lang.Object
  extended by org.perfectjpattern.core.behavioral.visitor.AbstractVisitor<E>
Type Parameters:
E - Element type that this IVisitor can visit.
All Implemented Interfaces:
IVisitor<E>
Direct Known Subclasses:
PrintVisitor, ToStringVisitor

public abstract class AbstractVisitor<E>
extends Object
implements IVisitor<E>

Reusable abstract base implementation of IVisitor interface.

Version:
$Revision: 1.0 $ $Date: Jul 1, 2007 7:02:55 AM $
Author:
Giovanni Azua
See Also:
IVisitor
 

Constructor Summary
AbstractVisitor()
           
 
Method Summary
static
<E> void
reusableVisit(IVisitor<E> aVisitor, E... anElements)
          Reusable implementation of the visit method that may be reused by implementors of IVisitor that for any reason can not subclass AbstractVisitor.
 void visit(E anElement)
          Abstract definition of the Visitor's Pattern visit method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractVisitor

public AbstractVisitor()
Method Detail

visit

public final void visit(E anElement)
Abstract definition of the Visitor's Pattern visit method. This method will alone handle the dynamic double-dispatch operation avoiding the need for a counterpart accept method in the IElement hierarchy. First the visit method will resolve to the base Visitor implementation's by dynamic invocation i.e. overriding. Then the base Visitor implementation will lookup automatically by a second dynamic dispatch mechanism the right Visitor's visit implementation depending on the concrete IElement sub-type.

Specified by:
visit in interface IVisitor<E>
Parameters:
anElement - IElement instance to visit.

reusableVisit

public static <E> void reusableVisit(IVisitor<E> aVisitor,
                                     E... anElements)
                          throws IllegalArgumentException
Reusable implementation of the visit method that may be reused by implementors of IVisitor that for any reason can not subclass AbstractVisitor.

Type Parameters:
E - Type of Element to visit.
Parameters:
aVisitor - Concrete IVisitor instance.
anElements - Concrete IElement instances to visit.
Throws:
IllegalArgumentException - 'aVisitor' must not be null.
IllegalArgumentException - 'anElements' must not be null.
IllegalArgumentException - 'anElements' must not be empty.


Copyright © 2007-2009. All Rights Reserved.