Monday, November 14, 2005

Notes on visitor design pattern

The operations or the behavior of classes are implemented by concrete implementation of visitors.
Concrete visitors are implementation of visitor interface where overloaded "visit" methods are defined, one for each class that needs a visitor.
A class that supports visitor defined a method called "allowVisitor" with argument of visitor interface. The method calls the "visit" method passing "this" as argument.
The advantage of visitor pattern is that new functionality can be added without touching the existing classes but the disadvantage is that the concrete visitor probably needs to know each supportable classes in detail.