Inheritance: Prototype.AbstractPrototype
Exemple #1
0
        static void Main(string[] args)
        {
            // Create two instances and clone each
            Telo   T1 = new Telo(10, "ggg");
            System s1 = new ConcretePrototype1(T1);
            System c1 = s1.Clone();

            c1.SsS.DLINA = 8;
            c1.SsS.NAME  = "rrrrrr";

            Console.WriteLine("Dlina: {0} Name: {1}", c1.SsS.DLINA, c1.SsS.NAME);

            Console.WriteLine("Dlina: {0} Name: {1}", s1.SsS.DLINA, s1.SsS.NAME);

            Telo   T2 = new Telo(50, "hohoho");
            System s2 = new ConcretePrototype2(T2);
            System c2 = s2.Clone();

            c2.SsS.DLINA = 25;
            c2.SsS.NAME  = "zozozo";

            Console.WriteLine("Dlina: {0} Name: {1}", c2.SsS.DLINA, c2.SsS.NAME);

            Console.WriteLine("Dlina: {0} Name: {1}", s2.SsS.DLINA, s2.SsS.NAME);


            // Wait for user
            Console.Read();
        }
        static void Main(string[] args)
        {
            Resume resumeA = new Resume("大鳥");

            resumeA.SetPersonlInfo("男", 29);
            resumeA.SetWorkExperience("1998-2000", "XX公司");

            Resume resumeB = (Resume)resumeA.Clone();

            resumeB.SetWorkExperience("1998-2006", "YY企業");

            Resume resumeC = (Resume)resumeA.Clone();

            resumeC.SetPersonlInfo("男", 24);
            resumeC.SetWorkExperience("1998-2003", "ZZ企業");

            resumeA.Display();
            resumeB.Display();
            resumeC.Display();

            Console.WriteLine("\n");

            ConcretePrototype1 prototype1 = new ConcretePrototype1("My name is YoChen");
            ConcretePrototype1 prototype2 = (ConcretePrototype1)prototype1.Clone();

            Console.WriteLine($"Clone: {prototype2.Id}");

            Console.ReadLine();
        }
Exemple #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("                       Service    Operator    City    Provider     InComm  OutComm");
            Console.WriteLine("");


            //yeni nesneyi oluştırduk
            ConcretePrototype1 CPT1 = new ConcretePrototype1("Topup", "All", "İzmir", "CyberPlat", new Commission(1.0, 0.5));

            Console.WriteLine("Original Object:          {0}       {1}        {2}     {3}      {4}    {5} "
                              , CPT1.Service, CPT1.Operator, CPT1.City, CPT1.Provider, CPT1.Comm.IncomingCommission, CPT1.Comm.OutgoingCommission);
            Console.WriteLine("");


            //birinci nesneyi yopyalarak
            //yeni nesnenin üzerinde değişikler yaptım
            ConcretePrototype1 CPT2 = (ConcretePrototype1)CPT1.Clone();

            Console.WriteLine("new object after Copying the original one:     {0}      {1}      {2}    {3}    {4}     {5}"
                              , CPT2.Service, CPT2.Operator, CPT2.City, CPT2.Provider, CPT2.Comm.IncomingCommission, CPT2.Comm.OutgoingCommission);
            Console.WriteLine("");

            CPT2.City     = "İstanbul";
            CPT2.Provider = "Euronet";
            CPT2.Comm.IncomingCommission = 0.75;
            CPT2.Comm.OutgoingCommission = 0.25;

            Console.WriteLine("changes in the copied object:        {0}      {1}        {2}   {3}    {4}    {5}"
                              , CPT2.Service, CPT2.Operator, CPT2.City, CPT2.Provider, CPT2.Comm.IncomingCommission, CPT2.Comm.OutgoingCommission);
            Console.WriteLine("");



            Console.ReadKey();
        }
Exemple #4
0
        static void Main(string[] args)
        {
            ConcretePrototype1 p1 = new ConcretePrototype1("1");
            ConcretePrototype1 c1 = (ConcretePrototype1)p1.Clone();

            Console.WriteLine(p1.Id + c1.Id);
            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            Prototype prototype = new ConcretePrototype1(1);
            Prototype clone     = prototype.Clone();

            prototype = new ConcretePrototype2(2);
            clone     = prototype.Clone();
        }
Exemple #6
0
        static void Main()
        {
            Prototype prototype = null;
            Prototype original  = null;

            prototype = new ConcretePrototype1(1);
            original  = prototype.Clone();

            prototype = new ConcretePrototype2(2);
            original  = prototype.Clone();
        }
Exemple #7
0
        static void Main(string[] args)
        {
            Prototype prototype = new ConcretePrototype1(10, 15, 23);
            Prototype clone     = prototype.Clone();

            prototype = new ConcretePrototype2(14, 5, 50);
            clone     = prototype.Clone();

            prototype = new Triangle(10, 14, 50);;
            clone     = prototype.Clone();
        }
    static void Main()
    {
      // Create two instances and clone each 
      Prototype prototype1 = new ConcretePrototype1("I");
      Prototype clonedPrototype1 = prototype1.Clone();
      Console.WriteLine ("Cloned: {0}", clonedPrototype1 .Id);
 
      Prototype prototype2 = new ConcretePrototype2("II");
      Prototype clonedPrototype2 = prototype2.Clone();
      Console.WriteLine ("Cloned: {0}", clonedPrototype2 .Id);
    }
Exemple #9
0
        static void Main(string[] args)
        {
            Prototype prototype;
            Prototype original;

            prototype = new ConcretePrototype1(1);
            original  = prototype.Clone();

            prototype = new ConcretePrototype2(2);
            original  = prototype.Clone();
        }
Exemple #10
0
        static void Main(string[] args)
        {
            Prototype prototype = null;
            Prototype clone = null;

            prototype = new ConcretePrototype1(1);
            clone = prototype.Clone();

            prototype = new ConcretePrototype2(2);
            clone = prototype.Clone();
        }
Exemple #11
0
        static void Main()
        {
            Prototype prototype1       = new ConcretePrototype1("I");
            Prototype clonedPrototype1 = prototype1.Clone();

            Console.WriteLine("Cloned: {0}", clonedPrototype1.Id);

            Prototype prototype2       = new ConcretePrototype2("II");
            Prototype clonedPrototype2 = prototype2.Clone();

            Console.WriteLine("Cloned: {0}", clonedPrototype2.Id);
        }
Exemple #12
0
        static void Main(string[] args)
        {
            ConcretePrototype1 p1 = new ConcretePrototype1("I");
            ConcretePrototype1 c1 = (ConcretePrototype1)p1.Clone();
            Console.WriteLine("Cloned: {0}", c1.Id);

            ConcretePrototype2 p2 = new ConcretePrototype2("II");
            ConcretePrototype2 c2 = (ConcretePrototype2)p2.Clone();
            Console.WriteLine("Cloned: {0}", c2.Id);
            
            Console.ReadKey();
        }
Exemple #13
0
        static void Main(string[] args)
        {
            ConcretePrototype1 cp1 = new ConcretePrototype1("CP1");
            ConcretePrototype1 pc1 = (ConcretePrototype1)cp1.Clone();

            Console.WriteLine("{0}", pc1.Id);
            ConcretePrototype1 cp2 = new ConcretePrototype1("CP2");
            ConcretePrototype1 pc2 = (ConcretePrototype1)cp2.Clone();

            Console.WriteLine("{0}", pc2.Id);
            Console.ReadLine();
        }
Exemple #14
0
        private static void Main()
        {
            ConcretePrototype1 p1 = new ConcretePrototype1("This is Concrete 1");
            ConcretePrototype1 c1 = (ConcretePrototype1)p1.Clone();

            Console.WriteLine("Cloned: {0}", c1.Id);
            ConcretePrototype2 p2 = new ConcretePrototype2("This is Concrete 2");
            ConcretePrototype2 c2 = (ConcretePrototype2)p2.Clone();

            Console.WriteLine("Cloned: {0}", c2.Id);
            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            ConcretePrototype1 p1 = new ConcretePrototype1("1");
            ConcretePrototype1 c1 = (ConcretePrototype1)p1.Clone();

            Console.WriteLine("Cloned: {0}", c1.Id);
            ConcretePrototype2 p2 = new ConcretePrototype2("2");
            ConcretePrototype2 c2 = (ConcretePrototype2)p2.Clone();

            Console.WriteLine("Cloned: {0}", c2.Id);
            Console.ReadKey();
        }
Exemple #16
0
        static void Main(string[] args)
        {
            ConcretePrototype1 concretePrototype1 = new ConcretePrototype1("I");
            ConcretePrototype1 c1 = (ConcretePrototype1)concretePrototype1.Clone();
            ConcretePrototype2 concretePrototype2 = new ConcretePrototype2("II");
            ConcretePrototype2 c2 = (ConcretePrototype2)concretePrototype2.Clone();

            Console.WriteLine("Cloned: " + c1.Id);
            Console.WriteLine("Cloned: " + c2.Id);

            Console.ReadKey();
        }
        /// <summary>
        /// Entry point into console application.
        /// </summary>
        static void Main()
        {
            // Create two instances and clone each
            ConcretePrototype1 p1 = new ConcretePrototype1("I");
            ConcretePrototype1 c1 = (ConcretePrototype1)p1.Clone();

            Console.WriteLine("Cloned: {0}", c1.Id);

            ConcretePrototype2 p2 = new ConcretePrototype2("II");
            ConcretePrototype2 c2 = (ConcretePrototype2)p2.Clone();

            Console.WriteLine("Cloned: {0}", c2.Id);
        }
Exemple #18
0
        static void Main(string[] args)
        {
            Prototype prototype = null;
            Prototype clone     = null;

            prototype = new ConcretePrototype1(1);
            clone     = prototype.Clone();
            Console.WriteLine(clone.Id);
            prototype = new ConcretePrototype2(2);
            clone     = prototype.Clone();
            Console.WriteLine(clone.Id);
            Console.ReadKey();
        }
Exemple #19
0
        static void Main(string[] args)
        {
            ConcretePrototype1 p1 = new ConcretePrototype1("A");
            ConcretePrototype2 p2 = new ConcretePrototype2("B");

            ConcretePrototype1 pc1 = (ConcretePrototype1)p1.Clone();
            ConcretePrototype2 pc2 = (ConcretePrototype2)p2.Clone();

            Console.WriteLine("Cloned : " + pc1.Id);
            Console.WriteLine("Cloned : " + pc2.Id);

            Console.ReadKey();
        }
Exemple #20
0
        static void Main()
        {
            // Create two instances and clone each
            Prototype prototype1       = new ConcretePrototype1("I");
            Prototype clonedPrototype1 = prototype1.Clone();

            Console.WriteLine("Cloned: {0}", clonedPrototype1.Id);

            Prototype prototype2       = new ConcretePrototype2("II");
            Prototype clonedPrototype2 = prototype2.Clone();

            Console.WriteLine("Cloned: {0}", clonedPrototype2.Id);
        }
Exemple #21
0
        static void Main(string[] args)
        {
            //Создания двух экземпляров и клонирование их.
            ConcretePrototype1 p1 = new ConcretePrototype1("1");
            ConcretePrototype1 c1 = p1.Clone() as ConcretePrototype1;

            Console.WriteLine("Clonned: {0}", c1.Id);

            ConcretePrototype2 p2 = new ConcretePrototype2("2");
            ConcretePrototype2 c2 = p2.Clone() as ConcretePrototype2;

            Console.WriteLine("Clonned: {0}", c2.Id);
        }
Exemple #22
0
        /// <summary>
        /// Entry point into console application.
        /// </summary>
        static void Main()
        {
            // Create two instances and clone each
            ConcretePrototype1 p1 = new ConcretePrototype1("I");
            ConcretePrototype1 c1 = (ConcretePrototype1)p1.Clone();
            Console.WriteLine("Cloned: {0}", c1.Id);

            ConcretePrototype2 p2 = new ConcretePrototype2("II");
            ConcretePrototype2 c2 = (ConcretePrototype2)p2.Clone();
            Console.WriteLine("Cloned: {0}", c2.Id);

            // Wait for user
            Console.ReadKey();
        }
Exemple #23
0
        static void Main(string[] args)
        {
            ConcretePrototype1 p1    = new ConcretePrototype1("1610207");
            ConcretePrototype1 copy1 = (ConcretePrototype1)p1.Clone();

            Console.WriteLine("Cloned: {0}", copy1.ID);

            ConcretePrototype2 p2    = new ConcretePrototype2("La Quoc Thang");
            ConcretePrototype2 copy2 = (ConcretePrototype2)p2.Clone();

            Console.WriteLine("Cloned: {0}", copy2.ID);

            Console.ReadKey();
        }
Exemple #24
0
        static void Main()
        {
            ConcretePrototype1
                p1 = new ConcretePrototype1("I"),
                c1 = (ConcretePrototype1)p1.Clone();

            Console.WriteLine("Cloned: {0}", c1.Id);

            ConcretePrototype2
                p2 = new ConcretePrototype2("II"),
                c2 = (ConcretePrototype2)p2.Clone();

            Console.WriteLine("Cloned: {0}", c2.Id);
        }
Exemple #25
0
        static void Main(string[] args)
        {
            ConcretePrototype p1 = new ConcretePrototype("I");
            ConcretePrototype c1 = (ConcretePrototype)p1.Clone();

            Console.WriteLine("Cloned: {0}", c1.Id);

            ConcretePrototype1 p2 = new ConcretePrototype1("II");
            ConcretePrototype1 c2 = (ConcretePrototype1)p2.Clone();

            Console.WriteLine("Cloned: {0}", c2.Id);

            // Wait for user
            Console.ReadKey();
        }
Exemple #26
0
        static void Main(string[] args)
        {
            ConcretePrototype1 p1       = new ConcretePrototype1("p1");
            ConcretePrototype1 clonedP1 = (ConcretePrototype1)p1.Clone();

            Console.WriteLine(clonedP1.Id);
            Console.WriteLine(p1.Equals(clonedP1));

            ConcretePrototype2 p2       = new ConcretePrototype2("p2");
            ConcretePrototype2 clonedP2 = (ConcretePrototype2)p2.Clone();

            Console.WriteLine(clonedP2.Id);
            Console.WriteLine(p2.Equals(clonedP2));

            Console.Read();
        }
        static void Main(string[] args)
        {
            AbstractPrototype prototype1 = new ConcretePrototype1("One");
            AbstractPrototype clonePrototype1 = prototype1.Clone();

            AbstractPrototype prototype2 = new ConcretePrototype1("Two");
            AbstractPrototype clonePrototype2 = prototype2.Clone();

            Console.WriteLine("First prototype: {0}", prototype1.GetId());
            Console.WriteLine("First prototype copy: {0}", clonePrototype1.GetId());

            Console.WriteLine("Second prototype: {0}", prototype2.GetId());
            Console.WriteLine("Second prototype copy: {0}", clonePrototype2.GetId());

            Console.Read();
        }
Exemple #28
0
        static void Main()
        {
            // Create two instances and clone each
            var p1 = new ConcretePrototype1("I");
            var c1 = (ConcretePrototype1)p1.Clone();

            Console.WriteLine("Cloned: {0}", c1.Id);

            var p2 = new ConcretePrototype2("II");
            var c2 = (ConcretePrototype2)p2.Clone();

            Console.WriteLine("Cloned: {0}", c2.Id);

            // Wait for user
            Console.Read();
        }
        static void Main()
        {
            // Создание двух экземпляров и клонирование их.
            ConcretePrototype1 p1 = new ConcretePrototype1("1");
            ConcretePrototype1 c1 = p1.Clone() as ConcretePrototype1;

            Console.WriteLine("Cloned: {0}", c1.Id);

            ConcretePrototype2 p2 = new ConcretePrototype2("2");
            ConcretePrototype2 c2 = p2.Clone() as ConcretePrototype2;

            Console.WriteLine("Cloned: {0}", c2.Id);

            // Задержка.
            Console.ReadKey();
        }
Exemple #30
0
        static void Main(string[] args)
        {
            //原型模式测试1
            ConcretePrototype1 p1 = new ConcretePrototype1("1");
            ConcretePrototype1 p2 = (ConcretePrototype1)p1.Clone();

            Console.WriteLine("p1: " + p1.Id);
            Console.WriteLine("p2: " + p2.Id);
            //原型模式测试1 END


            //原型模式举例说明1
            Console.WriteLine("报名面点师");
            RestrationInfo restrationInfo1 = new RestrationInfo("小面");

            restrationInfo1.Birthday = "1992-2-2";
            restrationInfo1.School   = "清华大学";
            restrationInfo1.Id       = "001";

            //展示报名信息
            restrationInfo1.Show();
            //报名厨师
            Console.WriteLine("报名一级厨师");
            RestrationInfo restartion2 = restrationInfo1.Clone() as RestrationInfo;

            restartion2.Show();
            //原型模式举例说明End


            //原型模式举例说明2
            Console.WriteLine("报名面点师");
            DeepRestrationInfo deepRestrationInfo1 = new DeepRestrationInfo("小面");

            deepRestrationInfo1.Birthday = "1992-2-2";
            deepRestrationInfo1.School   = "清华大学";
            deepRestrationInfo1.Id       = "001";
            deepRestrationInfo1.SetNation("美国");

            //报名厨师
            Console.WriteLine("报名一级厨师");
            DeepRestrationInfo deepRestartion2 = deepRestrationInfo1.DeepClone() as DeepRestrationInfo;

            deepRestartion2.SetNation("中国");
            deepRestrationInfo1.Show();
            deepRestartion2.Show();
            //原型模式举例说明End
        }
Exemple #31
0
        public static void Run()
        {
            Console.WriteLine("This structural code demonstrates the Prototype pattern in which new objects are created by copying pre-existing objects (prototypes) of the same class.");
            ConcretePrototype1 p1 = new ConcretePrototype1("I");
            ConcretePrototype1 c1 = (ConcretePrototype1)p1.Clone();

            Console.WriteLine("Cloned: {0}", c1.Id);
            ConcretePrototype2 p2 = new ConcretePrototype2("II");
            ConcretePrototype2 c2 = (ConcretePrototype2)p2.Clone();

            Console.WriteLine("Cloned: {0}", c2.Id);

            /*
             * Cloned: I
             * Cloned: II
             */
        }
Exemple #32
0
        static void Main(string[] args)
        {
            // Create two instances and clone each

            ConcretePrototype1 p1 = new ConcretePrototype1("I");
            ConcretePrototype1 c1 = (ConcretePrototype1)p1.Clone();

            Console.WriteLine("Cloned: {0}", c1.Id);

            ConcretePrototype2 p2 = new ConcretePrototype2("II");
            ConcretePrototype2 c2 = (ConcretePrototype2)p2.Clone();

            Console.WriteLine("Cloned: {0}", c2.Id);

            // Wait for user
            Console.ReadKey();
        }
Exemple #33
0
        static void Main()
        {
            // Create two instances and clone each

            ConcretePrototype1 p1 = new ConcretePrototype1("I");
            ConcretePrototype1 c1 = (ConcretePrototype1)p1.Clone();

            MessageBox.Show("Cloned: " + c1.Id);

            ConcretePrototype2 p2 = new ConcretePrototype2("II");
            ConcretePrototype2 c2 = (ConcretePrototype2)p2.Clone();

            MessageBox.Show("Cloned: " + c2.Id);

            //Application.EnableVisualStyles();
            //Application.SetCompatibleTextRenderingDefault(false);
            //Application.Run(new Form1());
        }
        static void Main1(string[] args)
        {
            // Create two instances and clone each

            ConcretePrototype1 p1 = new ConcretePrototype1("I");

            Console.WriteLine("Cloned: {0}", p1.Id);
            ConcretePrototype1 client1 = (ConcretePrototype1)p1.Clone();

            Console.WriteLine("Cloned: {0}", client1.Id);

            ConcretePrototype2 p2      = new ConcretePrototype2("II");
            Prototype          client2 = p2.Clone();

            Console.WriteLine("Cloned: {0}", client2.Id);

            Console.ReadKey();
        }
Exemple #35
0
        static void Main(string[] args)
        {
            var prototype = new ConcretePrototype1
            {
                Property1        = "A",
                Property2        = "B",
                PrototypeDetails = new PrototypeDetails {
                    Details = "prototype details"
                }
            };

            var NewObject = prototype.Clone() as ConcretePrototype1;

            NewObject.PrototypeDetails.Details = "New details for 'NewObject'";

            Console.WriteLine(prototype);
            Console.WriteLine(NewObject);


            var prototype2 = new ConcretePrototype2
            {
                Property1        = "X",
                Property2        = "Y",
                OtherProperty    = "Z",
                PrototypeDetails = new PrototypeDetails {
                    Details = "prototype2 details"
                }
            };

            var NewObject2 = prototype2.Clone() as ConcretePrototype2;

            NewObject2.PrototypeDetails.Details = "New details for 'NewObject2'";

            Console.WriteLine(prototype2);
            Console.WriteLine(NewObject2);

            Console.ReadKey();
        }
Exemple #36
0
        static void Main(string[] args)
        {
            #region 工厂方法
            double total = 0.0d;
            CashContext cc = new CashContext(new CashNormal());
            total = cc.GetResult(100.04);
            cc = new CashContext(new CashRebate("0.8"));
            total = cc.GetResult(100.04);
            Console.WriteLine(total);
            #endregion

            #region 装饰器方法
            Decorator.Component person = new Decorator.Component("xiaocai");

            Tshirt tshirt = new Tshirt();
            BigTrouser bt = new BigTrouser();

            bt.Decorator(person);
            tshirt.Decorator(bt);
            tshirt.show();

            Console.WriteLine("*****************************");
            #endregion

            #region 代理方法
            SchoolGirl sg = new SchoolGirl();
            sg.Name = "李娇骄";
            Proxy.Proxy daili = new Proxy.Proxy(sg);
            daili.GiveDolls();
            daili.GiveFlowers();
            #endregion

            #region 原型模式
            ConcretePrototype1 p1 = new ConcretePrototype1("123");
            ConcretePrototype1 c1 = (ConcretePrototype1)p1.Clone();
            Console.WriteLine("Cloned :"+c1.Id);

            Resume a = new Resume("Andy");
            a.setInfo("Man", "24");
            a.setWorkExperience("1998-2005","IBM ");
            Resume b = (Resume)a.Clone();
            b.setWorkExperience("2002-2005", "Dell");
            a.display();
            b.display();
            #endregion

            #region 模板模式
            Console.WriteLine("Student A testPaper:");
            TestPaperA testA = new TestPaperA();
            testA.Test1();
            testA.Test2();
            Console.WriteLine("Student B testPaper:");
            TestPaperB testB = new TestPaperB();
            testB.Test1();
            testB.Test2();
            #endregion

            #region 抽象工厂方法
            User user = new User();

            IFactory factory = new SqlServerFactory();
            IUser iu = factory.CreateUser();
            //IUser riu = (IUser)Assembly.Load("AbstractFactory").CreateInstance("SqlserverUser");
            //反射
            //Assembly.Load("程序集名称").CreateInstance("程序集名称.类名称");
            iu.Insert(user);
            iu.GetUser(1);
            #endregion

            #region Facade 外观模式
            Fund jijin = new Fund();
            jijin.BuyFund();
            jijin.sellFund();
            #endregion

            #region 建造者模式
            Director director = new Director();
            abstractBuilder builder1 = new Builder1();
            abstractBuilder builder2 = new BuilderB();
            director.Construct(builder1);
            Builder.Builder b1 = builder1.getBuilder();
            b1.show();

            director.Construct(builder2);
            Builder.Builder b2 = builder2.getBuilder();
            b2.show();
            #endregion
            #region 观察者模式
            Observer.ConcreteSubject s = new Observer.ConcreteSubject();
            s.Attach(new Observer.ConcreteObserver(s, "x"));
            s.Attach(new Observer.ConcreteObserver(s, "y"));
            s.SubjectState = "ABC";
            s.Notify();
            ///下面是使用委托
            ///委托就是一种引用方法的类型。一旦为委托分配了方法,委托将于该方法具有完全相同的行为。
            ///委托方法的使用可以像其他的方法一样具有参数和返回值。委托可以看作是对函数的抽象,是函数的”类“,委托的实例将代表一个具体的函数
            ///一个委托可以搭载多个方法,所有方法被依次唤起,委托搭载的方法不需要属于同一个类,只需要具有相同的原型和形式,也就是拥有相同的参数列表和返回类型。
            ///在使用带参数的委托时,只需要在声明事件的地方将参数传递给事件。在绑定时将调用的方法绑定给事件。
            Bosscs boss = new Bosscs();
            StockObserver tongshi1 = new StockObserver("tongshi1",boss);
            NBAObserver tongshiNBA = new NBAObserver("tongshiNBA", boss);
            boss.Update += new EventHandler1(tongshi1.CloseStockMarket);
            boss.Update += new EventHandler1(tongshiNBA.CloseStockMarket);
            boss.update2 += new EventHandler2(tongshiNBA.print);
            boss.SubjectState = " I am back ";
            boss.Notify();
            #endregion

            #region 状态模式
            State.Context c = new State.Context(new CreateStateA());
            c.Request();
            c.Request();
            c.Request();
            c.Request();

            #endregion

            #region 备忘录模式
            Originator o = new Originator();
            o.State = "On";
            o.Show();
            Caretaker care = new Caretaker();
            care.Memento = o.CreateMemento();
            o.State = "Off";
            o.Show();

            o.SetMemento(care.Memento);
            o.Show();

            GameRole gameRole = new GameRole();
            gameRole.GetInitState();
            gameRole.StateDisplay();

            RoleStateManager stateManager = new RoleStateManager();
            stateManager.Memento = gameRole.SaveState();

            gameRole.Fight();
            gameRole.StateDisplay();

            gameRole.RecoveryState(stateManager.Memento);
            gameRole.StateDisplay();
            #endregion

            #region 组合模式
            Composite.Composite root = new Composite.Component("root");
            root.Add(new Leaf("Leaf A"));
            root.Add(new Leaf("Leaf B"));

            Composite.Composite comp = new Composite.Component("comp X");
            comp.Add(new Leaf("Leaf XA"));
            comp.Add(new Leaf("Leaf XB"));
            root.Add(comp);

            Composite.Composite comp2 = new Composite.Component("Comp X2");
            comp2.Add(new Leaf("Leaf X2A"));
            comp2.Add(new Leaf("Leaf X2B"));
            comp.Add(comp2);

            root.Add(new Leaf("Leaf C"));
            Leaf leaf = new Leaf("Leaf D");

            root.Add(leaf);
            root.Display(1);
            root.Remove(leaf);
            root.Display(1);
            #endregion

            #region 迭代器模式
            ConCreteAggregate aggregate = new ConCreteAggregate();
            aggregate[0] = "大鸟";
            aggregate[1] = "小菜";
            aggregate[2]="行李";
            aggregate[3] = "老外";
            aggregate[4] = "小偷";
            Iterator.Iterator myIterator = new ConCreteIterator(aggregate);
            object item = myIterator.First();
            while (!myIterator.IsDone())
            {
                Console.WriteLine(myIterator.CurrentItem() + "请买车票");
                myIterator.Next();
            }
            #endregion

            #region 单例模式
             //所有类都有构造方法,不编码则默认生成空的构造方法,若有显示定义的构造方法,默认的构造方法就会失效。只要将构造方法改写为私有的,外部的程序就不能通过new 来初始化它。
            //通过一个共有的方法来返回类的实例。
            Singleton.Singleton s1 = Singleton.Singleton.GetInstance();
            Singleton.Singleton s2 = Singleton.Singleton.GetInstance();

            if (s1 == s2)
            {
                Console.WriteLine("两个对象是相同的实例。");
            }

            #endregion

            #region 命令模式
            Receiver r = new Receiver();
            Command.Command command = new Command.ConcreteCommand(r);
            Invoker invoker = new Invoker();
            invoker.SetCommand(command);
            invoker.ExecuteCommand();
            #endregion

            #region 职责链模式
            Handler h1 = new ConcreteHandler1();
            Handler h2 = new ConcreteHandler2();
            h1.SetSuccessor(h2);
            int[] requests = { 2, 3, 4, 5, 6, 12, 34, 11, 15 };
            foreach (int request in requests)
            {
                h1.HandlerRequest(request);
            }
            #endregion

            #region 中介者模式
            ConcreteMediator mediator = new ConcreteMediator();
            ConcreteColleague1 colleague1 = new ConcreteColleague1(mediator);
            ConcreteColleague2 colleague2 = new ConcreteColleague2(mediator);
            mediator.Colleague1 = colleague1;
            mediator.Colleague2 = colleague2;
            colleague1.Send("吃饭了吗?");
            colleague2.Send("还没有呢");
            #endregion

            #region 享元模式
            int extri = 22;
            FlyweightFactory f = new FlyweightFactory();
            Flyweight.Flyweight fx = f.GetFlyweight("X");
            fx.Operation(--extri);

            Flyweight.Flyweight fy = f.GetFlyweight("Y");
            fy.Operation(--extri);

            Flyweight.Flyweight fz = f.GetFlyweight("Z");
            fz.Operation(--extri);

            #endregion

            #region 解释器模式
            <<<<<<< HEAD
            Interpreter.Context context = new Interpreter.Context();
            IList<Interpreter.AbstractExpression> list = new List<Interpreter.AbstractExpression>();
            list.Add(new Interpreter.TerminalExpression());
            list.Add(new Interpreter.NormalExpression());
            foreach (Interpreter.AbstractExpression exp in list)
                exp.Interpret(context);
            =======
            Interpreter.Context context1 = new Interpreter.Context();
            IList<AbstractExpression> list = new List<AbstractExpression>();
            list.Add(new TerminalExpression());
            list.Add(new NonTerminalExpression());
            foreach (AbstractExpression exp in list)
            {
                exp.Interpreter(context1);
            }
            #endregion

            #region 访问者模式
            ObjectStructure os = new ObjectStructure();
            os.Add(new Man());
            os.Add(new Woman());
            Success v1 = new Success();
            os.Display(v1);
            Failing f1 = new Failing();
            os.Display(f1);

            Amativeness a1 = new Amativeness();
            os.Display(a1);
            >>>>>>> 77e342ef6e96917a8dc01e72e41626dcffd4ba13
            #endregion
            Console.Read();
        }