The Visitor Pattern – Part 1

We can now derive from TShapeVisitor to achieve the different behaviour. For instance, to draw on a TCanvas we would have something like this:

It is worth to mention that the units Graphics and Types are only used in the new visitor unit. There is no reference to them in the unit describing the shapes.

The other visitors can be implemented in a similar way keeping all the specific stuff (Inifiles, OpenGL, XML) inside the visitor unit. This allows to only include the visitors we actually need and doesn’t pollute our uses clause with units we don’t want in our application.

More in Part 2…

Author: Uwe Raabe

Addicted to Pascal/Delphi since the late 70's

One thought on “The Visitor Pattern – Part 1”

  1. Thanks for an excellent article on the visitor pattern. I have heard a lot of talk regarding patterns, but all very abstract in its descriptions. This one really makes it easy to understand.

    Jan

Comments are closed.