Hi there, i have a question regarding the visitor pattern, I currently have two assemblies. My first assembly contains several interfaces.
public interface INode
{
void Visit(INodeVisitor visitor);
}
public interface INodeVisitor
{
void VisitContainer(IContainer container);
}
public interface IContainer : INode
{
}
And my second assembly
class Program
{
static void Main(string[] args)
{
ContainerVisitor visitor = new ContainerVisitor();
visitor.VisitContainer(new Container());
}
}
public class ContainerVisitor : INodeVisitor
{
public void VisitContainer(IContainer value)
{
Container container = value as Container;
// Do some stuff...
}
}
public class Container : IContainer
{
public void Visit(INodeVisitor visitor)
{
visitor.VisitContainer(this);
}
}
What i want to do is avoid the need to cast in the ContainerVisitor class, I want to reference the Container directly. I cannot change the interface INodeVisitor interface to use Container. Any ideas? Should i just cast?
Cheers
Rohan