static void Main(string[] args)
        {
            ConcreteMediator  m  = new ConcreteMediator();
            ConcreteColleage1 c1 = new ConcreteColleage1(m);//讓2個具體同事類別認識仲介者
            ConcreteColleage2 c2 = new ConcreteColleage2(m);

            m.Colleage1 = c1;
            m.Colleage2 = c2;

            c1.Send("今天吃什麼?");
            c2.Send("不知道");

            Console.ReadKey();
        }
Exemple #2
0
        public static void Run()
        {
            Console.WriteLine("This structural code demonstrates the Mediator pattern facilitating loosely coupled communication between different objects and object types. The mediator is a central hub through which all interaction must take place.\n");

            ConcreteMediator   m  = new ConcreteMediator();
            ConcreteColleague1 c1 = new ConcreteColleague1(m);
            ConcreteColleage2  c2 = new ConcreteColleage2(m);

            m.Colleague1 = c1;
            m.Colleague2 = c2;

            c1.Send("How are you?");
            c2.Send("Fine, thanks");

            /*
             * Colleague2 gets message: How are you?
             * Colleague1 gets message: Fine, thanks
             */
        }