Revisiting Visitors

    In preparing for the second section of inquiry for this project ie. Generics & Design Patterns I realized that my conception of the visitor design pattern did not match with the classical view. I set about to find what in the classical view I disagreed with and why. Since Design Patterns by Gamma et. al. is the definitive patterns book I looked to it as the classical view. I realized from this that what is actually written encompassed my view but was somewhat biased toward the more classical view. What follows is a section by section discussion of where I take issue with their discussion of the visitor design pattern.

    In general the discussion is good except for the problems listed above. In addition I would extend the discussion by suggesting that the visitor can be used in more diverse situations to provide a hook on an abstract class hierarchy for variant behavior. Indeed it can be useful to provide an accept method for objects which are not even part of an abstract hierarchy to provide this hook. For example, consider a string class. If one attempted to provide all possible string operations that class would be far to big and constantly updated. By providing a visitor only the minimal set of operations would be on the string class and operations could be added dynamically through the visitor hook.