Esempio n. 1
0
 public override void Process(Request request)
 {
     request.Price *= 0.9;
 }
Esempio n. 2
0
        public void TestMethod()
        {
            IHandler handler1 = new InternalHandler();
            IHandler handler2 = new DiscountHandler();
            IHandler handler3 = new MailHandler();
            IHandler handler4 = new RegularHandler();

            //组合链式结构
            //internal->mail->discount->retular->null
            handler1.Successor = handler3;
            handler3.Successor = handler2;
            handler2.Successor = handler4;
            IHandler head = handler1;

            Request request = new Request(20, PurchaseType.Mail);
            head.HandleRequest(request);

            Console.ReadLine();
        }
Esempio n. 3
0
 //需要具体IHandler类型处理的内容
 public abstract void Process(Request request);
Esempio n. 4
0
 public override void Process(Request request)
 {
 }
Esempio n. 5
0
 //按照链式方式依次把调用继续下去
 public virtual void HandleRequest(Request request)
 {
     if (request == null) return;
     if (request.Type == Type)
         Process(request);
     else
         if (Successor != null)
             successor.HandleRequest(request);
 }