コード例 #1
0
        static void Main(string[] args)
        {
            var mediator = new Mediator1();

            var colleague1 = new Colleague1(mediator);
            var colleague2 = new Colleague2(mediator);
            var colleague3 = new Colleague3(mediator);

            mediator.Colleague1 = colleague1;
            mediator.Colleague2 = colleague2;
            mediator.Colleague3 = colleague3;

            colleague1.Send($"Hello, my name is {nameof(colleague1)}!");
            Console.WriteLine();

            colleague2.Send($"Hello, my name is {nameof(colleague2)}!");
            Console.WriteLine();

            colleague3.Send($"Hello, my name is {nameof(colleague3)}!");
            Console.WriteLine();
        }
コード例 #2
0
        public override void Send(string message, Colleague colleague)
        {
            if (colleague is Colleague1)
            {
                Colleague2.Receive(message);
                Colleague3.Receive(message);
                return;
            }

            if (colleague is Colleague2)
            {
                Colleague1.Receive(message);
                Colleague3.Receive(message);
                return;
            }

            if (colleague is Colleague3)
            {
                Colleague1.Receive(message);
                Colleague2.Receive(message);
                return;
            }
        }