Chapter 32. The Visitor Pattern

The Visitor pattern turns the tables on our object-oriented model and creates an external class to act on data in other classes. This is useful when you have a polymorphic operation that cannot reside in the class hierarchy for some reason—for example, because the operation wasn't considered when the hierarchy was designed or it would clutter the interface of the classes unnecessarily. The Visitor pattern is easier to explain using VB7, since polymorphism and inheritance make the code rather simpler. We'll discuss how to implement the Visitor in VB6 at the end of this chapter.

Motivation

While at first it may seem “unclean” to put operations inside one class that should be in another, there are good reasons for doing ...

Get Visual Basic Design Patterns: VB 6.0 and VB.NET now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.