Represent an operation to be performed on the elements of an object structure. Visitor lets you define a new operation without changing the classes of the elements on which it operates.
PerfectJPattern's componentized version of the Visitor Pattern differs from the original GoF version in that:
IVisitor<E>
type for each new Concrete Element type. The AbstractVisitor<E>.visit(<E>)
method or its static variation reusableVisit
handle all Element subtypes via double-dispatch. accept(...)
method. AbstractVisitor<E>
implementation that provides the double-dispatch mechanism implemented on top of PerfectJPattern's Delegates. Adding new Concrete Visitor is as simple as extending AbstractVisitor<E>
(or otherwise reusing the static reusableVisit
implementation) and implementing the relevant visitXXX(...)
methods for each Element subtype of interest. Concrete Visitors' visit method names may be chosen freely, though a good convention would be to use visitXXX(...)
but it is not compulsory.