示例#1
0
        static void Main()
        {
            ConcreteObjectA      a  = new ConcreteObjectA();
            ConcreteObjectB      b  = new ConcreteObjectB();
            StronglyTypedVisitor sv = new StronglyTypedVisitor();

            //proper usage of code
            a.AcceptVisitor(sv);
            b.AcceptVisitor(sv);

            //now lets try to do some tricks
            GenericVisitor gv = new GenericVisitor();

            try
            {
                //a.AcceptVisitor(gv); this will generate compile error
                (a as IObject).AcceptVisitor(gv);       //oooo Im so great!
            }
            catch (ArgumentException ae)
            {
                Console.WriteLine("—————————————————————————————n{0}", ae);
            }


            //example with synchronization lost!
            try
            {
                //Im sure it was agreed that the GeneralVisitor accepts ConcreteB, maybe its just a bug, I will try with the interface
                //b.AcceptVisitor(gv); //this will generate compile error
                (b as IObject).AcceptVisitor(gv);       //looks fine to me and the compilator, so it works!
            }
            catch (ArgumentException ae)
            {
                Console.WriteLine("—————————————————————————————n{0}", ae);
            }

            Console.ReadKey();
        }
示例#2
0
 public void HandleVisit(ConcreteObjectB aObject)
 {
     Console.WriteLine("Visited by a strongly typed ObjectB instance");
 }
示例#3
0
 public void HandleVisit(ConcreteObjectB aObjectB)
 {
     Console.WriteLine("Handle visit of class {0}", aObjectB);
 }