Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var o = new ObjectStruture();

            o.Anexar(new ConcreteElementA());
            o.Anexar(new ConcreteElementB());

            var v1 = new ConcreteVisitor1();
            var v2 = new ConcreteVisitor2();

            o.Accept(v1);
            o.Accept(v2);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            var objectoEstrutucre = new Objectestructure();

            objectoEstrutucre.Anexar(new ConcretElementA());
            objectoEstrutucre.Anexar(new ConcretElementB());

            var visitor1 = new ConcreteVisitor1();
            var visitor2 = new ConcreteVisitor2();

            objectoEstrutucre.Accpet(visitor1);
            objectoEstrutucre.Accpet(visitor2);
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            Visitor v1 = new ConcreteVisitor1();
            Visitor v2 = new ConcreteVisitor2();
            Element e1 = new ConcreteElementA();
            Element e2 = new ConcreteElementB();

            e1.Accept(v1);
            e2.Accept(v1);
            Console.WriteLine("————————————");
            e1.Accept(v2);
            e2.Accept(v2);
            Console.ReadLine();
        }
Exemplo n.º 4
0
    {   //define uma nova operaçao para uma classe sem alteraçao
        static void Main(string[] args)
        {
            ObjectEstruture objectEstruture = new ObjectEstruture();

            objectEstruture.Anexar(new ConcreteElementA());
            objectEstruture.Anexar(new ConcreteElementB());

            ConcreteVisitor1 visitor1 = new ConcreteVisitor1();
            ConcreteVisitor2 visitor2 = new ConcreteVisitor2();


            objectEstruture.Accept(visitor1);
            objectEstruture.Accept(visitor2);
        }
Exemplo n.º 5
0
    static void Main()
    {
      ObjectStructure o = new ObjectStructure();
      o.Attach(new ConcreteElementA());
      o.Attach(new ConcreteElementB());
 
      ConcreteVisitor1 v1 = new ConcreteVisitor1();
      ConcreteVisitor2 v2 = new ConcreteVisitor2();
 
      o.Accept(v1);
      o.Accept(v2);
 
      Console.ReadKey();
    }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            ObjectStruture o = new ObjectStruture();

            o.Anexar(new ConcreteElementA());
            o.Anexar(new ConcreteElementB());

            ConcretVisitor1  v1 = new ConcretVisitor1();
            ConcreteVisitor2 v2 = new ConcreteVisitor2();

            o.Aceept(v1);
            o.Aceept(v2);

            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            ObjectStructure objectStructure = new ObjectStructure();

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

            ConcreteVisitor1 concreteVisitor1 = new ConcreteVisitor1();
            ConcreteVisitor2 concreteVisitor2 = new ConcreteVisitor2();

            objectStructure.Accept(concreteVisitor1);
            objectStructure.Accept(concreteVisitor2);

            Console.Read();
        }
        static void Main()
        {
            ObjectStructure obj = new ObjectStructure();

            obj.Attach(new ConcreteElementA());
            obj.Attach(new ConcreteElementB());

            ConcreteVisitor1 v1 = new ConcreteVisitor1();
            ConcreteVisitor2 v2 = new ConcreteVisitor2();

            obj.Accept(v1);
            obj.Accept(v2);

            Console.ReadKey();
        }
Exemplo n.º 9
0
        private static void Main()
        {
            var objectStructure = new ObjectStructure();

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

            var visitor1 = new ConcreteVisitor1();
            var visitor2 = new ConcreteVisitor2();

            objectStructure.Accept(visitor1);
            objectStructure.Accept(visitor2);

            Console.ReadKey();
        }
Exemplo n.º 10
0
        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);
        }
Exemplo n.º 11
0
        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();
        }
Exemplo n.º 12
0
        static void Main(string[] args)
        {
            SampleObjectStructure sampleObjectStructure = new SampleObjectStructure();

            sampleObjectStructure.Attach(new Man());
            sampleObjectStructure.Attach(new Woman());

            // 成功時的反應
            Action success = new Success();

            sampleObjectStructure.Display(success);

            // 失敗時的反應
            Action failing = new Failing();

            sampleObjectStructure.Display(failing);

            // 戀愛時的反應
            Action amativeness = new Amativeness();

            sampleObjectStructure.Display(amativeness);

            // 結婚時的反應
            Action marriage = new Marriage();

            sampleObjectStructure.Display(marriage);

            Console.WriteLine();

            ObjectStructure objectStructure = new ObjectStructure();

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

            Visitor concreteVisitor1 = new ConcreteVisitor1();
            Visitor concreteVisitor2 = new ConcreteVisitor2();

            objectStructure.Accept(concreteVisitor1);
            objectStructure.Accept(concreteVisitor2);

            Console.ReadLine();
        }
Exemplo n.º 13
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);
        }
Exemplo n.º 14
0
        public static void Run()
        {
            Console.WriteLine("This structural code demonstrates the Visitor pattern in which an object traverses an object structure and performs the same operation on each node in this structure. Different visitor objects define different operations.\n");
            ObjectStructure o = new ObjectStructure();

            o.Attach(new ConcreteElementA());
            o.Attach(new ConcreteElementB());

            ConcreteVisitor1 v1 = new ConcreteVisitor1();
            ConcreteVisitor2 v2 = new ConcreteVisitor2();

            o.Accept(v1);
            o.Accept(v2);

            /*
             * ConcreteElementA visited by ConcreteVisitor1
             * ConcreteElementB visited by ConcreteVisitor1
             * ConcreteElementA visited by ConcreteVisitor2
             * ConcreteElementB visited by ConcreteVisitor2
             */
        }
        static void Main(string[] args)
        {
            try
            {
                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);
            }
            finally
            {
                Console.ReadKey();
            }
        }
Exemplo n.º 16
0
        private static void Main(string[] args)
        {
            // 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();
        }