I have a question about visitor pattern! Imagine I have Data structure Class and inside it I have a has-a relation with Class2. Class2 has specific class hierarchy with about 10 classes.
I need to itetarate list of Class1 instances and dispatch request for Visitor.visit(Class1) according to type of Class2. I can't use iteration with class2 because I need variables from class1 context.
Right now I'm thinking something about dispatcher who accept Class1 object and then on the basis of this class it check type of class2 and call something
But in this case I loose same signature for visitor pattern...
Another question how can I inject variables in the context of the visitor pattern. like if I traverse tree structures I want to keep parent variable for previous level to perform something on the lower level.
以上就是Visitor pattern for Java的详细内容，更多请关注web前端其它相关文章！