Example #1
0
        static void Main(string[] args)
        {
            ObjectStructure objectStructure = new ObjectStructure();

            objectStructure.Add(new ConcreteElementA());
            objectStructure.Add(new ConcreteElementB());

            ConcreteVisitor1 cea = new ConcreteVisitor1();
            ConcreteVisitor2 ceb = new ConcreteVisitor2();

            objectStructure.Accept(cea);
            objectStructure.Accept(ceb);
            Console.ReadKey();
        }
Example #2
0
        static void Main(string[] args)
        {
            List <IComponent> components = new List <IComponent>
            {
                new ConcreteComponentA(),
                new ConcreteComponentB()
            };

            Console.WriteLine("The client code works with all visitors via the base Visitor interface:");
            var visitor1 = new ConcreteVisitor1();

            Client.ClientCode(components, visitor1);

            Console.WriteLine();

            Console.WriteLine("It allows the same client code to work with different types of visitors:");
            var visitor2 = new ConcreteVisitor2();

            Client.ClientCode(components, visitor2);
        }