コード例 #1
0
        static bool TestMediatorPattern()
        {
            Console.WriteLine("TESTING THE MEDIATOR DESIGN PATTERN: ");

            Participant <string> p1 = new ConcreteParticipant <string>("p1");
            Participant <string> p2 = new ConcreteParticipant <string>("p2");
            Participant <string> p3 = new ConcreteParticipant <string>("p3");

            Mediator <string> m = new ConcreteMediator <string>();

            m.Register(p1);
            m.Register(p2);
            m.Register(p3);

            p1.SendMessage(m, "Message from p1");
            //Output
            //p2 received: Message from p1
            //p3 received: Message from p1

            Console.ReadKey();

            return(true);
        }
コード例 #2
0
        public static void Main()
        {
            Participant john  = new ConcreteParticipant(Constants.DisplayJohn);
            Participant peter = new ConcreteParticipant(Constants.DisplayPeter);
            Participant nasko = new ConcreteParticipant(Constants.DisplayAtanas);

            ChatRoom chatRoom = new();

            chatRoom.Register(john);
            chatRoom.Register(peter);
            chatRoom.Register(nasko);

            john.Send(peter, "Hi Peter! How are you?");
            peter.Send(john, "Fine! Can you tell Atanas that the meeting will start at three o'clock?");
            john.Send(peter, "Yes.");
            peter.Send(john, "Thank you!");
            john.Send(nasko, "The meeting starts at three o'clock!");
            nasko.Send(john, "Fine, I will be there.");
            john.Send(peter, "Nasko is informed.");
            john.Send(peter, "Bye, see you at the meeting.");
            nasko.Send(peter, "Can you pick me up from home since my car is broken?");
            peter.Send(nasko, "No problem!");
            nasko.Send(peter, "Thank you, I really appreciate it!");
        }
コード例 #3
0
        static void Main(string[] args)
        {
            Participant jhon  = new ConcreteParticipant("Jhon");
            Participant peter = new ConcreteParticipant("Peter");
            Participant nasko = new ConcreteParticipant("Nasko");

            ChatRoom chatRoom = new ChatRoom();

            chatRoom.Register(jhon);
            chatRoom.Register(peter);
            chatRoom.Register(nasko);

            jhon.Send(peter, "Hi, Peter! How are you!");
            peter.Send(jhon, "Fine! Can you told Nasko that the meeting start at three o'clock.");
            jhon.Send(peter, "Yes");
            peter.Send(jhon, "Thank you!");
            jhon.Send(nasko, "The meeting start at three o'clock!");
            nasko.Send(jhon, "Fine, I will be there!");
            jhon.Send(peter, "Nasko is informed.");
            jhon.Send(peter, "Bye, to the meeting");
            nasko.Send(peter, "Can you take me from home because my car is broken.");
            peter.Send(nasko, "No problem!");
            nasko.Send(peter, "Thank you a lot, I really appreciate it!");
        }