示例#1
0
        public void Execute()
        {
            IColleague <string> colleague1 = new ConcreteColleague <string>("1");
            IColleague <string> colleague2 = new ConcreteColleague <string>("2");
            IColleague <string> colleague3 = new ConcreteColleague <string>("3");
            IColleague <string> colleague4 = new ConcreteColleague <string>("4");

            IMediator <string> mediator1 = new ConreteMediator <string>();

            mediator1.Register(colleague1);
            mediator1.Register(colleague2);
            mediator1.Register(colleague3);
            mediator1.Register(colleague4);

            colleague1.SendMessage(mediator1, "message X from 1");

            IMediator <string> mediator2 = new ConreteMediator <string>();

            mediator2.Register(colleague1);
            mediator2.Register(colleague2);
            mediator2.Register(colleague3);
            mediator2.Register(colleague4);

            colleague3.SendMessage(mediator2, "send Y from 3");
            colleague4.SendMessage(mediator2, "send massage from 4");
        }
示例#2
0
        static void Main16()
        {
            Console.WriteLine("Hello Mediator Pattern!");

            var platform = new ConcreteMediator();
            var a        = new ConcreteColleague("A", platform);
            var b        = new ConcreteColleague("B", platform);
            var c        = new ConcreteColleague("C", platform);
            var d        = new ConcreteColleague("D", platform);
            var e        = new ConcreteColleague("E", platform);

            a.JoinChat();
            b.JoinChat();
            c.JoinChat();
            d.JoinChat();
            e.JoinChat();

            a.SendMessage("Hello world!");
            b.SendMessage("Hello world!");
            c.SendMessage("Hello world!");
            d.SendMessage("Hello world!");
            e.SendMessage("Hello world!");

            a.LeaveChat();
            b.LeaveChat();
            c.LeaveChat();
            d.LeaveChat();
            e.LeaveChat();

            Console.ReadLine();
        }
        private (TestMessageWriter, ConcreteColleague) CreateConcreateCollegue(string name)
        {
            var messageWriter      = new TestMessageWriter();
            var concreateColleague = new ConcreteColleague(name, messageWriter);

            return(messageWriter, concreateColleague);
        }
    private void Start()
    {
        ConcreteMediator m = new ConcreteMediator();

        ConcreteColleague1 c1 = new ConcreteColleague1(m);
        ConcreteColleague2 c2 = new ConcreteColleague2(m);
        ConcreteColleague  c3 = new ConcreteColleague(m);
        ConcreteColleague  c4 = new ConcreteColleague(m);
        ConcreteColleague  c5 = new ConcreteColleague(m);
        ConcreteColleague  c6 = new ConcreteColleague(m);
        ConcreteColleague  c7 = new ConcreteColleague(m);

        //m.Colleague1 = c1;
        //m.Colleague2 = c2;
        m.AddColleague(c1);
        m.AddColleague(c2);
        m.AddColleague(c3);
        m.AddColleague(c4);
        m.AddColleague(c5);
        m.AddColleague(c6);
        m.AddColleague(c7);

        c1.Send("How are you?");
        c2.Send("Fine, thanks");
    }
        static void Main(string[] args)
        {
            //list of participants
            IColleague<string> colleagueA = new ConcreteColleague<string>("ColleagueA");
            IColleague<string> colleagueB = new ConcreteColleague<string>("ColleagueB");
            IColleague<string> colleagueC = new ConcreteColleague<string>("ColleagueC");
            IColleague<string> colleagueD = new ConcreteColleague<string>("ColleagueD");

            //first mediator
            IMediator<string> mediator1 = new ConcreteMediator<string>();
            //participants registers to the mediator
            mediator1.Register(colleagueA);
            mediator1.Register(colleagueB);
            mediator1.Register(colleagueC);
            //participantA sends out a message
            colleagueA.SendMessage(mediator1, "Message A from ColleagueA");

            //second mediator
            IMediator<string> mediator2 = new ConcreteMediator<string>();
            //participants registers to the mediator
            mediator2.Register(colleagueB);
            mediator2.Register(colleagueD);
            //participantB sends out a message
            colleagueB.SendMessage(mediator2, "Message B from ColleagueB");
        }
示例#6
0
        public void TestMethod1()
        {
            var mediator   = new ConcreteMediator();
            var colleague1 = new ConcreteColleague(mediator);
            var colleague2 = new ConcreteColleague(mediator);

            mediator.AddColleague(colleague1);
            mediator.AddColleague(colleague2);

            colleague1.Send("form C1");
            colleague2.Send("from C2");
        }
示例#7
0
        public void Start()
        {
            ConcreteMediator m = new ConcreteMediator();

            ConcreteColleague c1 = new ConcreteColleague(m, "Mike");
            ConcreteColleague c2 = new ConcreteColleague(m, "Jessica");
            ConcreteColleague c3 = new ConcreteColleague(m, "John");

            c1.Send("How are you?", c2);
            c2.Send("Fine, thanks", c1);
            c3.Send("Dinner tonight?", c2);
            c2.Send("Sounds great!", c3);
        }
示例#8
0
        static void Main(string[] args)
        {
            IColleague <string> colleagueA = new ConcreteColleague <string>("ColleagueA");
            IColleague <string> colleagueB = new ConcreteColleague <string>("ColleagueB");
            IColleague <string> colleagueC = new ConcreteColleague <string>("ColleagueC");

            IMediator <string> mediator1 = new ConcreteMediator <string>();

            mediator1.Register(colleagueA);
            mediator1.Register(colleagueB);
            mediator1.Register(colleagueC);

            colleagueA.SendMessage(mediator1, "MessageX from ColleagueA");
        }
示例#9
0
        static void Main(string[] args)
        {
            IColleague <string> colleagueA = new ConcreteColleague <string>("Colleague A");
            IColleague <string> colleagueB = new ConcreteColleague <string>("Colleague B");
            IColleague <string> colleagueC = new ConcreteColleague <string>("Colleague C");

            IMediator <string> mediator = new ConcreteMediator <string>();

            mediator.Register(colleagueA);
            mediator.Register(colleagueB);
            mediator.Register(colleagueC);

            colleagueC.SendMessage(mediator, "message from " + colleagueC.GetName() + "!");

            Console.ReadKey();
        }
示例#10
0
        static void Main(string[] args)
        {
            IColleague<string> colleagueA = new ConcreteColleague<string>("Colleague A");
            IColleague<string> colleagueB = new ConcreteColleague<string>("Colleague B");
            IColleague<string> colleagueC = new ConcreteColleague<string>("Colleague C");

            IMediator<string> mediator = new ConcreteMediator<string>();

            mediator.Register(colleagueA);
            mediator.Register(colleagueB);
            mediator.Register(colleagueC);

            colleagueC.SendMessage(mediator, "message from " + colleagueC.GetName() + "!");

            Console.ReadKey();
        }
示例#11
0
        public static void Test()
        {
            // Create chatroom participants
            AbstractColleague colleague1 = new ConcreteColleague() { ID = "1" };
            AbstractColleague colleague2 = new ConcreteColleague() { ID = "2" };
            AbstractColleague colleague3 = new ConcreteColleague() { ID = "3" };
            AbstractColleague colleague4 = new ConcreteColleague() { ID = "4" };
            AbstractColleague colleague5 = new ConcreteColleague() { ID = "5" };

            var mediator = new ConcreteMediator();
            mediator.Register(colleague1);
            mediator.Register(colleague2);
            mediator.Register(colleague3);
            mediator.Register(colleague4);
            mediator.Register(colleague5);

            colleague1.Send("2", "from 1 to 2");
            colleague3.Send("4", "from 3 to 4");
            colleague5.Send("1", "from 5 to 1");
        }