Exemple #1
0
        public void Test_Facebook_chat()
        {
            IChattingGroupMediator fbMediator   = new FacebookGroupMediator();
            IChattingGroupMediator instMediator = new InstagramGroupMediator();

            var userA = new ConcreteUser("User_name_A");
            var userB = new ConcreteUser("User_name_B");
            var userC = new ConcreteUser("User_name_C");
            var userD = new ConcreteUser("User_name_D");
            var userE = new ConcreteUser("User_name_E");
            var userF = new ConcreteUser("User_name_F");
            var userG = new ConcreteUser("User_name_G");

            fbMediator.RegisterUser(userA);
            fbMediator.RegisterUser(userC);
            fbMediator.RegisterUser(userE);
            fbMediator.RegisterUser(userF);

            instMediator.RegisterUser(userA);
            instMediator.RegisterUser(userB);
            instMediator.RegisterUser(userC);
            instMediator.RegisterUser(userD);
            instMediator.RegisterUser(userG);

            userA.SendMessageToFacebook("This is msg from userA");
            userE.SendMessageToFacebook("This is msg from userE");

            Assert.Throws <ArgumentNullException>(() => { userD.SendMessageToFacebook("This is msg from userA"); }, "This user does not participate in this facebook group.  (Parameter '_mediatorFacebook')");

            userA.SendMessageToInstagram("This is msg from userA");
            userB.SendMessageToInstagram("This is msg from userB");

            Assert.Throws <ArgumentNullException>(() => { userE.SendMessageToInstagram("This is msg from userA"); }, "This user does not participate in this instagram group.  (Parameter '_mediatorInstagram')");
        }
Exemple #2
0
        static void Main(string[] args)
        {
            Imediator mediator = new ConcreteMediator();
            IUser     user1    = new ConcreteUser(mediator);
            IUser     user2    = new ConcreteUser(mediator);

            mediator.AddUser(user1);
            mediator.AddUser(user2);
            user1.SendMessage("This is user number 1!");
            user2.SendMessage("This is user number 2!");
        }
Exemple #3
0
        private static void MediatorPattern()
        {
            #region Facebook Group

            FacebookGroupMediator facebookMediator = new ConcreteFacebookGroupMediator();
            FaceBookUser          Ram    = new ConcreteUser(facebookMediator, "Ram");
            FaceBookUser          Dave   = new ConcreteUser(facebookMediator, "Dave");
            FaceBookUser          Smith  = new ConcreteUser(facebookMediator, "Smith");
            FaceBookUser          Rajesh = new ConcreteUser(facebookMediator, "Rajesh");
            FaceBookUser          Sam    = new ConcreteUser(facebookMediator, "Sam");
            FaceBookUser          Pam    = new ConcreteUser(facebookMediator, "Pam");
            FaceBookUser          Anurag = new ConcreteUser(facebookMediator, "Anurag");
            FaceBookUser          John   = new ConcreteUser(facebookMediator, "John");
            facebookMediator.RegisterUser(Ram);
            facebookMediator.RegisterUser(Dave);
            facebookMediator.RegisterUser(Smith);
            facebookMediator.RegisterUser(Rajesh);
            facebookMediator.RegisterUser(Sam);
            facebookMediator.RegisterUser(Pam);
            facebookMediator.RegisterUser(Anurag);
            facebookMediator.RegisterUser(John);
            Dave.Send("dotnettutorials.net - this website is very good to learn Design Pattern");
            Console.WriteLine();
            Rajesh.Send("What is Design Patterns? Please explain ");

            #endregion Facebook Group

            #region Air Trafic Control

            IAirTraficControlMediator atcMediator = new AirTraficControlMediator();

            Flight flight1 = new ConreteFlight(atcMediator, 111);
            Flight flight2 = new ConreteFlight(atcMediator, 222);
            Flight flight3 = new ConreteFlight(atcMediator, 333);
            Flight flight4 = new ConreteFlight(atcMediator, 444);
            Flight flight5 = new ConreteFlight(atcMediator, 555);

            atcMediator.Register(flight1);
            atcMediator.Register(flight2);
            atcMediator.Register(flight3);
            atcMediator.Register(flight4);
            atcMediator.Register(flight5);

            Console.WriteLine();
            flight1.SendMessage("Where to land ??");
            Console.WriteLine();

            #endregion Air Trafic Control
        }
 public void Attach(ConcreteUser user)
 {
     _users.Add(user);
 }
 public void Detatch(ConcreteUser user)
 {
     _users.Remove(user);
 }