Esempio n. 1
0
 public override void Send(string message, Colleague colleague)
 {
     if (colleague == Colleague1)
     {
         Colleague2.Notify(message);
     }
     else
     {
         Colleague1.Notify(message);
     }
 }
 public void SendMessage(Colleague caller, string msg)
 {
     if (caller == Colleague1)
     {
         Colleague2.Receive(msg);
     }
     else
     {
         Colleague1.Receive(msg);
     }
 }
Esempio n. 3
0
        //public void Register(Colleague colleague)
        //{
        //    colleague.Mediator = this;
        //    _colleagues.Add(colleague);
        //}

        //public T CreateCollegue<T>() where T : Colleague, new()
        //{
        //    var c = new T {Mediator = this};
        //    _colleagues.Add(c);
        //    return c;
        //}

        public void Send(string message, Colleague colleague)
        {
            if (colleague == Colleague1)
            {
                Colleague2.HandleNotification(message);
            }
            else
            {
                Colleague1.HandleNotification(message);
            }

            //_colleagues.Where(c => c != colleague).ToList().ForEach(c => c.HandleNotification(message));
        }
Esempio n. 4
0
        private static void Main()
        {
            //var mediator = new ConcreteMediator();
            //var c1 = new Colleague1(mediator);
            //var c2 = new Colleague1(mediator);

            //mediator.Colleague1 = c1;
            //mediator.Colleague2 = c2;

            //c1.Send("Hello, World from c1");
            //c2.Send("Hello, World from c2");

            var mediator = new ConcreteMediator();
            var c1       = new Colleague1();
            var c2       = new Colleague1();

            mediator.Register(c1);
            mediator.Register(c2);

            c1.Send("Hello from c1");
            c2.Send("Hello from c2");
        }