Beispiel #1
0
        static void Main(string[] args)
        {
            Handler handlerA = new ConcreteHandlerA();
            Handler handlerB = new ConcreteHandlerB();
            Handler handlerC = new ConcreteHandlerC();

            handlerA.Successor = handlerB;
            handlerB.Successor = handlerC;
            handlerA.HandleRequest();

            Console.ReadLine();
        }
Beispiel #2
0
        private static void Main()
        {
            var concreteHandlerA = new ConcreteHandlerA();
            var concreteHandlerB = new ConcreteHandlerB();
            var concreteHandlerC = new ConcreteHandlerC();

            concreteHandlerA.SetSuccessor(concreteHandlerB);
            concreteHandlerB.SetSuccessor(concreteHandlerC);

            concreteHandlerA.HandleRequest("Request");

            Console.ReadKey();
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            Handler h1 = new ConcreteHandlerA();
            Handler h2 = new ConcreteHandlerB();
            Handler h3 = new ConcreteHandlerC();

            h1.SetSuccessor(h2);
            h2.SetSuccessor(h3);

            int[] requests = { 1, 5, 7, 19, 40, 23, 2, 10, 0 };

            foreach (var request in requests)
            {
                h1.HandleRequest(request);
            }

            Console.ReadKey();
        }
Beispiel #4
0
        private static void Main()
        {
            var concreteHandlerA = new ConcreteHandlerA();
            var concreteHandlerB = new ConcreteHandlerB();
            var concreteHandlerC = new ConcreteHandlerC();

            concreteHandlerA.SetSuccessor(concreteHandlerB);
            concreteHandlerB.SetSuccessor(concreteHandlerC);

            int[] requests = { 2, 5, 14, 22, 18, 3, 27, 20 };

            foreach (var request in requests)
            {
                concreteHandlerA.HandleRequest(request);
            }

            Console.ReadKey();
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            //实例化请求处理对象
            Handler h1 = new ConcreteHandlerA();
            Handler h2 = new ConcreteHandlerB();
            Handler h3 = new ConcreteHandlerC();

            //设置职责链的上下级关系
            h1.SetSuccessor(h2);
            h2.SetSuccessor(h3);
            int[] request = new int[] { 1, 3, 10, 16, 20, 22, 29, 31 };
            //传递不同请求值给请求处理者
            foreach (var req in request)
            {
                h1.RequestHandler(req);
            }

            Console.Read();
        }