O'Reilly logo

Design Patterns in Java™, Second Edition by William C. Wake, Steven John Metsker

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

29 Visitor

TO EXTEND AN existing class hierarchy, you normally just 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.

As with INTERPRETER, VISITOR is most often layered over a COMPOSITE. You may want to review that pattern, as we’ll use it throughout this chapter.

The intent of VISITOR ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required