Chapter 29. Visitor

To extend an existing class hierarchy, you normally simply add methods that provide the behavior you need. It can happen, though, that the behavior you need is not consistent with the thrust of the existing object model. It can also happen that you don't have access to the existing code. In such a case, it may be impossible to extend the hierarchy's behavior without modifying the hierarchy's classes. The VISITOR pattern, however, 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 you define a new operation for a hierarchy without changing the hierarchy classes.

Visitor Mechanics

The VISITOR pattern lets a small amount ...

Get Design Patterns in C# 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.