Summary
The VISITOR pattern lets you define a new operation for a hierarchy without changing the hierarchy classes. The mechanics for VISITOR 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 VISITOR, regularly ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access