예제 #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();
        }
예제 #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("我们没有核武器, 也不怕侵略");
        }
예제 #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("我们没研制核武器,也不怕侵略。");
        }
예제 #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("我们没研制核武器,也不怕侵略。");
        }
예제 #5
0
        /// <summary>
        /// 聯合國中介者
        /// </summary>
        public void ExcuteUnite()
        {
            UnitedNationsSecurityCouncil UNSC = new UnitedNationsSecurityCouncil();

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

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

            c1.Declare("開打");
            c2.Declare("來啊");
        }
예제 #6
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();
        }