Java Reference
In-Depth Information
CHALLENGE 29.5
List two alternatives to building V ISITOR into the Oozinoz machine and process
hierarchies.
Summary
The V ISITOR pattern lets you define a new operation for a hierarchy without changing the
hierarchy classes. The mechanics for V ISITOR include defining an interface for visitors and
adding accept() methods in the hierarchy that a visitor will call. The accept() methods
dispatch their calls back to the visitor in a double-dispatching scheme. This scheme arranges
for the execution of a visit() method that applies to the specific type of object from the
hierarchy.
A visitor developer must be aware of some, if not all, of the subtleties in the design of the
visited hierarchy. In particular, visitors need to beware of cycles that may occur in the visited
object model. This type of difficulty leads some developers to eschew V ISITOR , regularly
applying alternatives instead. Using V ISITOR should probably be a team decision that depends
on your methodology and the specifics of your application.
Search WWH ::




Custom Search