What is the need for Visitor Pattern in C#?You can implement
Visitor Pattern for your application when a class in your application
has to access information belonging to different objects which in turn
have different interfaces.
In Visitor Pattern, class that requires information from other classes is termed as visitor and the class from which information has to be retrieved is known as visited class. To implement Visitor Pattern, both these classes will include a new method as mentioned below: Visitor
class will include a method called visit which accepts the visited class
instance as parameter. Here is a
sample code content in Visited Class: 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) {
|