コード例 #1
0
        static void Main(string[] args)
        {
            //Cria-se o objeto mediador
            ChatMediator salaChat = new ChatMediator();

            //Criam-se os objetos participantes
            Participante joao   = new ParticipanteImpl("João", salaChat);
            Participante maria  = new ParticipanteImpl("Maria", salaChat);
            Participante carlos = new ParticipanteImpl("Carlos", salaChat);
            Participante renato = new ParticipanteImpl("Renato", salaChat);

            //Registra todos os participantes na sala de chat
            salaChat.RegistraParticipante(joao);
            salaChat.RegistraParticipante(maria);
            salaChat.RegistraParticipante(carlos);
            salaChat.RegistraParticipante(renato);

            //Inicia a conversa entre os participantes
            joao.EnviaMensagem("Maria", "Olá Maria, tudo bem ?");

            maria.EnviaMensagem("João", "Oi tudo! E com voc� ?");

            carlos.EnviaMensagem("Renato", "Renato, vocé é um @!xxx.");

            joao.EnviaMensagem("Maria", "Você está no trabalho agora ?");

            Console.ReadKey();
        }
コード例 #2
0
        static void Main(string[] args)
        {
            /*
             * More info: https://en.wikipedia.org/wiki/Mediator_pattern
             * What problems can the Mediator design pattern solve?
             * Tight coupling between a set of interacting objects should be avoided.
             * It should be possible to change the interaction between a set of objects independently.
             *
             * Defining a set of interacting objects by accessing and updating each other directly is inflexible because it tightly couples the objects to each other and makes
             * it impossible to change the interaction independently from (without having to change) the objects.
             *
             * And it stops the objects from being reusable and makes them hard to test.
             * Tightly coupled objects are hard to implement, change, test, and reuse because they refer to and know about many different objects.
             */

            IChatMediator mediator = new ChatMediator();
            IUser         user1    = new User(mediator, "Hamid");
            IUser         user2    = new User(mediator, "Lisa");
            IUser         user3    = new User(mediator, "Saurabh");
            IUser         user4    = new User(mediator, "David");
            IUser         vipUser  = new VipUser(mediator, "Hans");

            mediator.AddUser(user1);
            mediator.AddUser(user2);
            mediator.AddUser(user3);
            mediator.AddUser(user4);
            mediator.AddUser(vipUser);

            user1.Send("Hi All");
        }
コード例 #3
0
        static void Main(string[] args)
        {
            #region Lab_1
            IChatMediator chatMediator = new ChatMediator();
            IUser         hilal        = new BasicUser(chatMediator, "Beast");
            IUser         havva        = new GoldUser(chatMediator, "Savage");

            chatMediator.AddUser(hilal);
            chatMediator.AddUser(havva);

            hilal.SendMessage("Hello Suprise.");
            #endregion

            Console.WriteLine("\n");

            #region

            Arabulucu arabulucu = new Arabulucu();

            MainColleague merkez = new MainColleague(arabulucu, "Hilal Aslanboğa");
            Colleague_A   sube_1 = new Colleague_A(arabulucu, "Burak Yılmaz");
            merkez.Gonder("Cuma günü için bir toplantı düzenledim. Lütfen e-posta üzerinden onaylar mısınız?");
            sube_1.Gonder("Tabiki efendim kontrol ediyorum.");

            Colleague_A sube_2 = new Colleague_A(arabulucu, "Havva Kaya");
            sube_2.Gonder("Toplantıya katılamayacağım.");
            arabulucu.Engellenmis(merkez.TeslimAlma);

            sube_2.Gonder("Engellendim");
            merkez.Gonder("Toplantıda görüşürüz");

            #endregion

            Console.ReadKey();
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: RupeshGhosh10/Handson
        static void Main(string[] args)
        {
            var mediator = new ChatMediator();

            var user1 = new BasicUser(mediator, "user1");
            var user2 = new BasicUser(mediator, "user2");
            var user3 = new PremiumUser(mediator, "user3");

            mediator.AddUser(user2);
            mediator.AddUser(user3);

            user1.SendMessage("Hello");
        }
コード例 #5
0
        public static void EX2()
        {
            ChatMediator sala = new ChatMediator();

            Europeu  usuarioNaEuropa = new Europeu(sala);
            Africano usuarioNaAfrica = new Africano(sala);

            sala.AdicionarASala(usuarioNaEuropa);
            sala.AdicionarASala(usuarioNaAfrica);

            usuarioNaEuropa.EnviarMensagem("hello");
            usuarioNaAfrica.EnviarMensagem("hallo");

            usuarioNaEuropa.EnviarMensagem("message");
        }
コード例 #6
0
        static void Main(string[] args)
        {
            var mediator = new ChatMediator();

            var user1 = new BasicUser(mediator, "user1");
            var user2 = new BasicUser(mediator, "user2");


            mediator.AddUser(user1);
            mediator.AddUser(user2);

            user1.SendMessage("Hello");

            Console.ReadKey();
        }
コード例 #7
0
 public BasicUser(ChatMediator chatMediator, string name)
 {
     this.chatMediator = chatMediator;
     this.name         = name;
 }
コード例 #8
0
 public void SetChat(ChatMediator chat)
 {
     this.chat = chat;
     this.Send("entrato in chat!", null);
 }
コード例 #9
0
 public PremiumUser(ChatMediator chatMediator, string name)
 {
     this.chatMediator = chatMediator;
     this.name         = name;
 }