Visitor Controversy
VISITOR is a controversial pattern. Some developers consistently avoid applying it; others defend its use and suggest ways to strengthen it, although these suggestions usually add complexity. The fact is that many design problems tend to accompany the VISITOR pattern.
The fragility of VISITOR shows up in the examples in this chapter. For instance, in the MachineComponent hierarchy, the hierarchy developers decided to differentiate between Machine nodes and MachineComposite nodes but not to differentiate among Machine subclasses. If you need to distinguish among types of machines in your visitor, you will have to resort to using instanceof or another technique to tell which type of machine a visit() method has received. You ...
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