/// <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();
        }
Exemple #2
0
        /// <summary>
        /// Entry point into console application.
        /// </summary>
        static void Main()
        {
            // Create chatroom
            Chatroom chatroom = new Chatroom();

            Participant Eddie    = new Actor("Eddie");
            Participant Jennifer = new Actor("Jennifer");
            Participant Bruce    = new Actor("Bruce");
            Participant Tom      = new Actor("Tom");
            Participant Tony     = new NonActor("Tony");

            // Create participants and register them
            chatroom.Register(Eddie);
            chatroom.Register(Jennifer);
            chatroom.Register(Bruce);
            chatroom.Register(Tom);
            chatroom.Register(Tony);

            // Chatting participants
            Tony.Send("Tom", "Hey Tom! I got a mission for you.");
            Jennifer.Send("Bruce", "Teach me to act and I'll" +
                          " teach you to dance");
            Bruce.Send("Eddie", "How come you don't do standup anymore?");

            Jennifer.Send("Tom", "Do you like math?");
            Tom.Send("Tony", "Teach me to sing.");

            // 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();
        }
Exemple #4
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();
        }
Exemple #5
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'
             */
        }
        /// <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();
        }
Exemple #8
0
        static void Main(string[] args)
        {
            var chatroom = new Chatroom();

            var eddie = new Actor {
                Name = "Eddie"
            };
            var jennifer = new Actor {
                Name = "Jennifer"
            };
            var bruce = new Actor {
                Name = "Bruce"
            };
            var tom = new Actor {
                Name = "Tom"
            };
            var tony = new NonActor {
                Name = "Tony"
            };

            chatroom.Register(eddie);
            chatroom.Register(jennifer);
            chatroom.Register(bruce);
            chatroom.Register(tom);
            chatroom.Register(tony);

            tony.Send("Tom", "Hey Tom!");
            jennifer.Send("Bruce", "Teach me to act and I'll teach you to dance.");
            tom.Send("Tony", "teach me to sing!");

            Console.ReadKey();
        }
Exemple #9
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();
        }
Exemple #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");
        }
Exemple #11
0
        public void Run()
        {
            Chatroom chatroom = new Chatroom();

            Participant Eddie = new Actor("Eddie");
            Participant Jen   = new Actor("Jen");
            Participant Bruce = new Actor("Bruce");
            Participant Tom   = new Actor("Tom");
            Participant Tony  = new Actor("Tony");

            chatroom.Register(Eddie);
            chatroom.Register(Jen);
            chatroom.Register(Bruce);
            chatroom.Register(Tom);
            chatroom.Register(Tony);


            Tony.Send("Tom", "Hey Tom! I got a mission for you.");
            Jen.Send("Bruce", "Teach me to act and I'll teach you dance.");
            Bruce.Send("Eddie", "How come you don't do stanup anymore.");
            Jen.Send("Eddie", "Do you like math.");
            Tom.Send("Tony", "Teach me to sing");
        }
Exemple #12
0
        static void Main(string[] args)
        {
            Chatroom chatroom = new Chatroom();

            IParticipant roka   = new Participant("Roka");
            IParticipant john   = new Participant("John");
            IParticipant igor   = new Participant("Igor");
            IParticipant ruslan = new Participant("Ruslan");
            IParticipant bodya  = new Participant("Bodya");

            chatroom.Register(roka);
            chatroom.Register(john);
            chatroom.Register(igor);
            chatroom.Register(ruslan);
            chatroom.Register(bodya);

            roka.Send("all", "Hello, everybody!");
            john.Send("Roka", "Hi, Roka!");
            igor.Send("Ruslan", "How are you?");
            bodya.Send("Ruslan", "Do not answer!");
            ruslan.Send("Igor", "...");
            roka.Send("all", "Bye!");
        }
Exemple #13
0
        static void Main(string[] args)
        {
            Chatroom chatroom = new Chatroom();

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

            chatroom.Register(george);
            chatroom.Register(john);
            chatroom.Register(paul);
            chatroom.Register(ringo);
            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();
        }
Exemple #14
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");
        }
Exemple #15
0
        static void Main(string[] args)
        {
            Console.WriteLine("Mediator");

            var chat = new Chatroom();

            chat.Register(new Student("Adam"));
            chat.Register(new Student("Ewa"));
            chat.Register(new Student("Jolanta"));
            chat.Register(new Student("Mariusz"));
            chat.Register(new Teacher("Zygmunt"));
            chat.Register(new Teacher("Kornelia"));

            chat.Send("Adam", "Kornelia", "Jaki jest termin oddania projektu");
            chat.Send("Zygmunt", "Ewa", "Wyniki z kolowkium");
            chat.Send("Mariusz", "Jolanta", "Czy możesz pożyczyć notatki");
            chat.Send("Jolanta", "Mariusz", "Jasna sprawa");

            Console.ReadLine();
        }
        static void Main()
        {
            // Create chatroom
            Chatroom chatroom = new Chatroom();

            // Create colleagues and register them
            Colleague Ann = new FromMainCompant("Ann");
            Colleague Arthur = new FromMainCompant("Arthur");
            Colleague Jack = new FromMainCompant("Jack");
            Colleague John = new FromMainCompant("John");
            //Mery is from other company, but she can talk  with them
            Colleague Mery = new FromOtherCompany("Mery");

            chatroom.Register(Ann);
            chatroom.Register(Arthur);
            chatroom.Register(Jack);
            chatroom.Register(John);
            chatroom.Register(Mery);

            // Chatting colleagues
            Mery.Send("John", "Hi John!");
            Arthur.Send("Jack", "How are you?");
            Jack.Send("Ann", "Hello");
            Arthur.Send("John", "What are you doing John?");
            John.Send("Mery", "You are Welcome");
        }