예제 #1
0
        /// <summary>
        /// The handle.
        /// </summary>
        /// <param name="token">
        /// The token.
        /// </param>
        public override void Handle(ResponsibilityToken token)
        {
            Console.WriteLine("Обработчик {0}", this.Name);
            if (!token.HandlerIdList.Contains("D"))
            {
                return;
            }

            var x = token.Rnd.Next(2);

            if (x == 1)
            {
                Console.WriteLine("Произведена обработка {0}", this.Name);
                token.IsHandled = true;
            }
            else
            {
                if (this.Successor != null)
                {
                    Console.WriteLine("Передача управления на: {0}", this.Successor.Name);
                    this.Successor.Handle(token);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// The main.
        /// </summary>
        private static void Main()
        {
            PyamentHandler handlerD = new PyamentHandlerD {
                Name = "Handler D",
            };
            PyamentHandler handlerC = new PyamentHandlerC {
                Name = "Handler C", Successor = handlerD
            };
            PyamentHandler handlerB = new PyamentHandlerB {
                Name = "Handler B", Successor = handlerC
            };
            PyamentHandler handlerA = new PyamentHandlerA {
                Name = "Handler A", Successor = handlerB
            };
            var token = new ResponsibilityToken();

            token.AddHandler("A");
            token.AddHandler("B");
            token.AddHandler("C");
            token.AddHandler("D");

            handlerA.Handle(token);
            Console.ReadLine();
        }
예제 #3
0
 /// <summary>
 /// The handle.
 /// </summary>
 /// <param name="token">
 /// The token.
 /// </param>
 public abstract void Handle(ResponsibilityToken token);