Esempio n. 1
0
        static void Main(string[] args)
        {
            #region 中介者模式
            //实例化 具体中介者 联合国安理会
            UnitedNationsSecurityCouncil UNSC = new UnitedNationsSecurityCouncil();

            //实例化一个美国
            USA c1 = new USA(UNSC);
            //实例化一个里拉开
            Iraq c2 = new Iraq(UNSC);

            //将两个对象赋值给安理会
            //具体的中介者必须知道全部的对象
            UNSC.Register(c1);
            UNSC.Register(c2);

            //美国发表声明,伊拉克接收到
            c1.Declare("不准研制核武器,否则要发动战争!");

            //伊拉克发表声明,美国收到信息
            c2.Declare("我们没有核武器,也不怕侵略。");
            #endregion


            #region 中介者模式
            //步骤三:最后,通过mediator发送一个消息
            //var response = await mediator.Publish(new Ping());
            //Console.WriteLine(response); // "贠乾是个大帅哥"
            #endregion

            Console.Read();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            UnitedNationSecurityCouncil UNSC = new UnitedNationSecurityCouncil();
            USA  c1 = new USA(UNSC);
            Iraq c2 = new Iraq(UNSC);

            UNSC.ColleagueA = c1;
            UNSC.ColleaguaB = c2;

            c1.Declare("不准研制核武器, 否则发动战争");
            c2.Declare("我们没有核武器, 也不怕侵略");
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            UnitedNationsSecurityCouncil UNSC = new UnitedNationsSecurityCouncil();

            USA  c1 = new USA(UNSC);
            Iraq c2 = new Iraq(UNSC);

            UNSC.Country1 = c1;
            UNSC.Country2 = c2;

            c1.Declare("不准研制核武器,否则要发动战争!");
            c2.Declare("我们没研制核武器,也不怕侵略。");
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            UnitedNationsSecurityCouncil UNSC = new UnitedNationsSecurityCouncil();

            USA c1 = new USA(UNSC);
            Iraq c2 = new Iraq(UNSC);

            UNSC.Country1 = c1;
            UNSC.Country2 = c2;

            c1.Declare("不准研制核武器,否则要发动战争!");
            c2.Declare("我们没研制核武器,也不怕侵略。");
        }
Esempio n. 5
0
        //中介者
        public static void testMediator()
        {
            UnitedNationsSecurityCouncil UNSC = new UnitedNationsSecurityCouncil();

            USA  c1 = new USA(UNSC);
            Iraq c2 = new Iraq(UNSC);

            UNSC.Colleague1 = c1;
            UNSC.Colleague2 = c2;

            c1.Declare("不准研制核武器,否则要发动战争!");
            c2.Declare("我们没有核武器,也不怕侵略。");

            Console.Read();
        }