Chapter 29. Visitor

The ordinary way to extend a class hierarchy's behavior is to add methods that provide the behavior you need. It may happen, though, that the behavior you need is not consistent with the thrust of the existing object model. In other cases, the developer of a hierarchy may have little information about the behaviors that later developers will need.

If the developers who control the hierarchy code can't or won't change quickly enough to meet your needs, it may be impossible to extend the hierarchy's behavior without modifying the hierarchy's classes. But VISITOR lets a hierarchy developer build in support for the prospect that another developer may want to extend the behavior of the hierarchy. The intent of VISITOR is to let ...

Get Design Patterns Java™ Workbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.