static void Main() { // Setup structure ObjectStructure o = new ObjectStructure(); o.Attach(new ConcreteElementA()); o.Attach(new ConcreteElementB()); // Create visitor objects ConcreteVisitor1 v1 = new ConcreteVisitor1(); ConcreteVisitor2 v2 = new ConcreteVisitor2(); // Structure accepting visitors o.Accept(v1); o.Accept(v2); // Wait for user Console.ReadKey(); }
static void Main(string[] args) { List <Component> components = new List <Component> { new ConcreteComponentA(), new ConcreteComponentB() }; Console.Write("The client code works with all visitors via the base Visitor interface:\n"); var visitor1 = new ConcreteVisitor1(); Client.ClientCode(components, visitor1); Console.WriteLine(); Console.Write("It allows the same client code to work with different types of visitors:\n"); var visitor2 = new ConcreteVisitor2(); Client.ClientCode(components, visitor2); }