示例#1
0
        static void Main()
        {
            IMediator mediator = new Mediator();

            var talkColleague  = new ColleagueA(mediator);
            var fightColleague = new ColleagueB(mediator);

            talkColleague.Act();
            fightColleague.Act();
        }
示例#2
0
        static void Main(string[] args)
        {
            //一个房主、一个租房者、一个中介机构
            ConcertorMediator mediator = new ConcertorMediator();

            //房主和租房者只需要知道中介机构即可
            ColleagueA colleagueA = new ColleagueA("张三", mediator);
            ColleagueB colleagueB = new ColleagueB("李四", mediator);

            //中介结构要知道房主和租房者
            mediator.colleagueA = colleagueA;   //房主
            mediator.colleagueB = colleagueB;   //租房者

            colleagueB.PushMessage(" 听说你那里有三室的房主出租.....");
            colleagueA.PushMessage(" 是的!请问你需要租吗?");
        }
示例#3
0
        public void Register(AbstractColleague colleague)
        {
            switch (colleague)
            {
            case ColleagueA a:
                this.a = a;
                break;

            case ColleagueB b:
                this.b = b;
                break;

            default:
                break;
            }
        }
示例#4
0
        static void Main(string[] args)
        {
            Mediator   m       = new Mediator();
            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");
            m.Block(branch1.Receive);
            head1.Send("Still awaiting some Acks");
            head2.Send("Ack");
            m.Unblock(branch1.Receive);
            head1.Send("Thanks all");

            Console.ReadLine();
        }
示例#5
0
        static void Sample2()
        {
            Sample2.Mediator m       = new Sample2.Mediator();
            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");

            m.Block(branch1.Receive);
            head1.Send("Still awaiting some Acks");
            head2.Send("Ack");

            m.Unblock(branch1.Receive);
            head1.Send("Thanks all");
        }