
What
is the need for Visitor Pattern
|
Visitor
class will include a method called visit which accepts the visited class
instance as parameter.
Visited class will include a method called accept which accepts
the visitor class instance as parameter.
Here is
a sample code content in Visited Class:
public void accept(Visitor visitorObj) {
visitorObj.visit(this);
}
Now your visitor class has received an instance of visited class. Using this instance, visitor class can call accessible methods of visited class and retrieve the required information.
For example:
public void
visit(visitedClass obj) {
int number = obj.getNumber();
}
_______________________________________________________________________
FREE Subscription
Subscribe
to our mailing list and receive new articles
through email. Keep yourself updated with latest
developments in the industry.
Note
: We never rent, trade, or sell my email lists to
anyone.
We assure that your privacy is respected
and protected.
Visit .NET Programming Tutorial Homepage
______________________________________________________