Visitor pattern for Java

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 visitor.visitClass2Type1(Class1 object) 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前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准