Visitor Pattern is a type of behavioral design pattern. Wikipedia says: the visitor design pattern is a way of separating analgorithm from an object structure it operates on. A practical result of this separation is the ability to add new operations to existing object structures without modifying those structures.
Example:
Class A{
public void accept(Visitor v){
v.visit();
}
...
}
public interface Visitor {
public void visit(Class1 c);
public void visit(Class2 c);
...
}
public class CallingClass implements Visitor{
A objA;
SomeMethod(){
//as soon as following line is called, the visit class is called from objA
objA.accept(this);
....
}
public void visit(Class1 c){
...
}
public void visit(Class2 c){
...
}
}
0 comments:
Post a Comment