/// <summary>
        /// Entry point into console application.
        /// </summary>
        static void Main()
        {
            // Create chatroom
            Chatroom chatroom = new Chatroom();

            // Create participants and register them
            Participant George = new Beatle("George");
            Participant Paul   = new Beatle("Paul");
            Participant Ringo  = new Beatle("Ringo");
            Participant John   = new Beatle("John");
            Participant Yoko   = new NonBeatle("Yoko");

            chatroom.Register(George);
            chatroom.Register(Paul);
            chatroom.Register(Ringo);
            chatroom.Register(John);
            chatroom.Register(Yoko);

            // Chatting participants
            Yoko.Send("John", "Hi John!");
            Paul.Send("Ringo", "All you need is love");
            Ringo.Send("George", "My sweet Lord");
            Paul.Send("John", "Can't buy me love");
            John.Send("Yoko", "My sweet love");

            // Wait for user
            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            //Create the mediator
            Chatroom chatroom = new Chatroom();

            Participant George = new Beatle("George");
            Participant Paul   = new Beatle("Paul");
            Participant Ringo  = new Beatle("Ringo");
            Participant John   = new Beatle("John");
            Participant Yoko   = new NonBeatle("Yoko");

            chatroom.Register(George);
            chatroom.Register(Paul);
            chatroom.Register(Ringo);
            chatroom.Register(John);
            chatroom.Register(Yoko);

            Yoko.Send("John", "Hi John!");
            Paul.Send("Ringo", "All you need is love");
            Ringo.Send("George", "My sweet Lord");
            Paul.Send("John", "Can't buy me love");
            John.Send("Yoko", "My sweet love");

            Console.ReadKey();
        }
Beispiel #3
0
        public static void Main(string[] args)
        {
            // Create chatroom
            var chatroom = new Chatroom();

            // Create participants and register them
            var george = new Beatle("George");
            var paul   = new Beatle("Paul");
            var ringo  = new Beatle("Ringo");
            var john   = new Beatle("John");
            var yoko   = new NonBeatle("Yoko");

            chatroom.Register(george);
            chatroom.Register(paul);
            chatroom.Register(ringo);
            chatroom.Register(john);
            chatroom.Register(yoko);

            // Chatting participants
            yoko.Send("John", "Hi John!");
            paul.Send("Ringo", "All you need is love");
            ringo.Send("George", "My sweet Lord");
            paul.Send("John", "Can't buy me love");
            john.Send("Yoko", "My sweet love");

            // Wait for user
            Console.ReadKey();
        }
Beispiel #4
0
        /// <summary>
        /// Entry point into console application.
        /// </summary>
        static void Main()
        {
            // Create chatroom
            Chatroom chatroom = new Chatroom();

            // Create participants and register them
            Participant George = new Beatle("George");
            Participant Paul = new Beatle("Paul");
            Participant Ringo = new Beatle("Ringo");
            Participant John = new Beatle("John");
            Participant Yoko = new NonBeatle("Yoko");

            chatroom.Register(George);
            chatroom.Register(Paul);
            chatroom.Register(Ringo);
            chatroom.Register(John);
            chatroom.Register(Yoko);

            // Chatting participants
            Yoko.Send("John", "Hi John!");
            Paul.Send("Ringo", "All you need is love");
            Ringo.Send("George", "My sweet Lord");
            Paul.Send("John", "Can't buy me love");
            John.Send("Yoko", "My sweet love");

            // Wait for user
            Console.ReadKey();
        }
        public static void Run()
        {
            Console.WriteLine("This real-world code demonstrates the Mediator pattern facilitating loosely coupled communication between different Participants registering with a Chatroom. The Chatroom is the central hub through which all communication takes place. At this point only one-to-one communication is implemented in the Chatroom, but would be trivial to change to one-to-many.\n");
            Chatroom chatroom = new Chatroom();

            Participant George = new Beatle("George");
            Participant Paul   = new Beatle("Paul");
            Participant Ringo  = new Beatle("Ringo");
            Participant John   = new Beatle("John");
            Participant Yoko   = new NonBeatle("Yoko");

            chatroom.Register(George);
            chatroom.Register(Paul);
            chatroom.Register(Ringo);
            chatroom.Register(John);
            chatroom.Register(Yoko);

            Yoko.Send("John", "Hi John!");
            Paul.Send("Ringo", "All you need is love");
            Ringo.Send("George", "My sweet Lord");
            Paul.Send("John", "Can't buy me love");
            John.Send("Yoko", "My sweet love");

            /*
             * To a Beatle: Yoko to John: 'Hi John!'
             * To a Beatle: Paul to Ringo: 'All you need is love'
             * To a Beatle: Ringo to George: 'My sweet Lord'
             * To a Beatle: Paul to John: 'Can't buy me love'
             * To a non-Beatle: John to Yoko: 'My sweet love'
             */
        }
        public void Main()
        {
            var chatRoom = new ChatRoom();

            Participant george = new Beatle("George");
            Participant paul   = new Beatle("Paul");
            Participant ringo  = new Beatle("Ringo");
            Participant john   = new Beatle("John");
            Participant yoko   = new NonBeatle("Yoko");

            chatRoom.Register(george);
            chatRoom.Register(paul);
            chatRoom.Register(ringo);
            chatRoom.Register(john);
            chatRoom.Register(yoko);


            yoko.Send("John", "Hi John!");
            paul.Send("Ringo", "All you need is love");
            ringo.Send("George", "My sweet Lord");
            paul.Send("John", "Can't buy me love");
            john.Send("Yoko", "My sweet love");


            Console.ReadKey();
        }
        /// <summary>
        /// The test first.
        /// </summary>
        private static void TestFirst()
        {
            // Create chatroom
            Chatroom chatroom = new Chatroom();

            // Create participants and register them
            Participant george = new Beatle("George");
            Participant paul   = new Beatle("Paul");
            Participant ringo  = new Beatle("Ringo");
            Participant john   = new Beatle("John");
            Participant yoko   = new NonBeatle("Yoko");

            chatroom.Register(george);
            chatroom.Register(paul);
            chatroom.Register(ringo);
            chatroom.Register(john);
            chatroom.Register(yoko);

            // Chatting participants
            yoko.Send("John", "Hi John!");
            paul.Send("Ringo", "All you need is love");
            ringo.Send("George", "My sweet Lord");
            paul.Send("John", "Can't buy me love");
            john.Send("Yoko", "My sweet love");

            // Wait for user
            Console.ReadKey();
        }
Beispiel #8
0
        static void Main(string[] args)
        {
            // Crear sala de chat

            Chatroom chatroom = new Chatroom();



            // Crea participantes y regístralos.

            Participant George = new Beatle("George");

            Participant Paul = new Beatle("Paul");

            Participant Ringo = new Beatle("Ringo");

            Participant John = new Beatle("John");

            Participant Yoko = new NonBeatle("Yoko");



            chatroom.Register(George);

            chatroom.Register(Paul);

            chatroom.Register(Ringo);

            chatroom.Register(John);

            chatroom.Register(Yoko);



            // participantes en el chat

            Yoko.Send("John", "Hi John!");

            Paul.Send("Ringo", "All you need is love");

            Ringo.Send("George", "My sweet Lord");

            Paul.Send("John", "Can't buy me love");

            John.Send("Yoko", "My sweet love");



            // Esperando a usar

            Console.ReadKey();
        }
Beispiel #9
0
        static void Main()
        {
            /*
             * Structural Mediator
             */
            StructuralConcreteMediator m = new StructuralConcreteMediator();

            StructuralConcreteColleague1 c1 = new StructuralConcreteColleague1(m);
            StructuralConcreteColleague2 c2 = new StructuralConcreteColleague2(m);

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

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

            /*
             *  Real-World Mediator
             */

            Chatroom chatroom = new Chatroom();

            Participant george = new Beatle("George");
            Participant paul   = new Beatle("Paul");
            Participant ringo  = new Beatle("Ringo");
            Participant john   = new Beatle("John");
            Participant yoko   = new NonBeatle("Yoko");

            List <Participant> participantList = new List <Participant>()
            {
                george, paul, ringo, john, yoko
            };

            foreach (var beatle in participantList)
            {
                chatroom.Register(beatle);
            }

            // Chatting participants
            yoko.Send("John", "Hi John!");
            paul.Send("Ringo", "All you need is love");
            ringo.Send("George", "My sweet Lord");
            paul.Send("John", "Can't buy me love");
            john.Send("Yoko", "My sweet love");
        }
Beispiel #10
0
        static void Main(string[] args)
        {
            Chatroom chatroom = new Chatroom();

            Colleague colleague1 = new Beatle("colleague1");

            chatroom.Register(colleague1);
            Colleague colleague2 = new Beatle("colleague2");

            chatroom.Register(colleague2);
            Colleague colleague3 = new Beatle("colleague3");

            chatroom.Register(colleague3);


            colleague1.Send("colleague2", "ni hao");
            colleague2.Send("colleague3", "zai ma");
            colleague3.Send("colleague1", "zai");
        }
Beispiel #11
0
        static void Main(string[] args)
        {
            SohbetOdasi sohbetodasi = new SohbetOdasi();

            Katilimci ibrahim  = new Beatle("İbrahim");
            Katilimci zehra    = new Beatle("Zehra");
            Katilimci mehmet   = new Beatle("Mehmet");
            Katilimci ayten    = new Beatle("Ayten");
            Katilimci ibrahim2 = new Beatle("İbrahim2");

            sohbetodasi.Kayit(ibrahim);
            sohbetodasi.Kayit(zehra);
            sohbetodasi.Kayit(mehmet);
            sohbetodasi.Kayit(ayten);
            sohbetodasi.Kayit(ibrahim2);

            ibrahim2.Gonder("Ayten", "Selam Ayten");
            zehra.Gonder("Mehmet", "1 2 3 4 5");
            mehmet.Gonder("İbrahim", "6 7 8  9");
            zehra.Gonder("Ayten", "10 12");
            ayten.Gonder("İbrahim2", "O lala");
        }