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.