The Visitor Pattern – Part 3

Now we can write a visitor that just counts the shapes visited:

Pretty easy and effective, isn’t it?

But there is still some drawback, as the visitor is limited to visit TAbstractShape and its descendants. What if we have other classes to visit that don’t fit in this inheritance scheme? Can’t we find a more general approach? Here it is:

With this TAbstractShape or any other class to be visited has to implement IVisited and we are done.

More in Part 4…

Author: Uwe Raabe

Addicted to Pascal/Delphi since the late 70's

The Art of Delphi Programming
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.