Exemplo n.º 1
0
        static void Main()
        {
            var mediator        = new Mediator();
            var firstColleague  = new ColleagueA(mediator);
            var secondColleague = new ColleagueB(mediator);

            firstColleague.Send();
            secondColleague.Receive();
            mediator.SendMessage(firstColleague);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            Mediator m = new Mediator();
            // Two from head office and one from a branch office
            Colleague  head1   = new Colleague(m, "John");
            ColleagueB branch1 = new ColleagueB(m, "David");
            Colleague  head2   = new Colleague(m, "Lucy");

            head1.Send("Meeting on Tuesday, please all ack");
            branch1.Send("Ack");      // by design does not get a copy
            m.Block(branch1.Receive); // temporarily gets no messages
            head1.Send("Still awaiting some Acks");
            head2.Send("Ack");
            m.Unblock(branch1.Receive); // open again
            head1.Send("Thanks all");
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            Mediator   m      = new Mediator();
            Colleague  head1  = new Colleague(m, "Megha");
            ColleagueB branch = new ColleagueB(m, "Test");
            Colleague  head2  = new Colleague(m, "Mohit");


            head1.Send("Meeting is there in Thursday, Plesae ack");
            branch.Send("Ack");
            m.Block(branch.Receive);
            head1.Send("Still waiting for Ack ");
            head2.Send("Ack");
            m.UnBlock(branch.Receive);
            head1.Send("Thanks All");
            Console.ReadLine();
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            Console.WriteLine("Using structural code : ");
            Console.WriteLine();

            Mediator mediator = new Mediator();

            ColleagueA colleagueA = new ColleagueA(mediator);
            ColleagueB colleagueB = new ColleagueB(mediator);

            mediator.ColleagueA = colleagueA;
            mediator.ColleagueB = colleagueB;

            colleagueA.Send("Hi! I'm colleagueA");
            colleagueB.Send("Hi! I'm colleagueB");

            Console.ReadLine();

            Console.WriteLine("Using real-world code : ");
            Console.WriteLine();

            Console.ReadLine();
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            ConcreteMediator mediator = new ConcreteMediator();

            ColleagueA colleagueA = new ColleagueA(mediator);
            ColleagueB colleagueB = new ColleagueB(mediator);

            mediator.SetColleagueA(colleagueA);
            mediator.SetColleagueB(colleagueB);

            colleagueB.Send("Hello A");
            colleagueA.Send("Hello B");


            CustomerServericeMM customerMM = new CustomerServericeMM();
            Customer            customer   = new Customer(customerMM);
            Techician           techician  = new Techician(customerMM);

            customerMM.SetCustomer(customer);
            customerMM.SetTechicain(techician);

            customer.Ask("客户提问");
            techician.Answer("技术支持解答");
        }
Exemplo n.º 6
0
 public Mediator(ColleagueA colleagueA, ColleagueB colleagueB)
 {
     this.ColleagueA = colleagueA;
     this.ColleagueB = colleagueB;
 }
Exemplo n.º 7
0
 public MediatorB(ColleagueA colleagueA, ColleagueB colleagueB)
     : base(colleagueA, colleagueB)
 {
 }
Exemplo n.º 8
0
 public void SetColleagueB(ColleagueB colleagueB)
 {
     this.colleagueB = colleagueB;
 }