示例#1
0
 public virtual void HandleRequest(string input)
 {
     if (Next != null)
     {
         Next.HandleRequest(input);
     }
 }
示例#2
0
 protected void ForwardRequest(Request request)
 {
     Console.WriteLine("Forwarding request");
     if (successor != null)
     {
         successor.HandleRequest(request);
     }
 }
示例#3
0
        static void Main(string[] args)
        {
            Handler h = InitializeHandler();

            foreach (var i in new int[] { 3, 4, 6, 11, 12 })
            {
                h.HandleRequest(i);
            }

            Console.ReadKey();
        }
示例#4
0
 public virtual void HandleRequest(int request)
 {
     if (request >= this.from && request < this.to)
     {
         Console.WriteLine("{0} handled request for {1}", this.GetType().Name, request);
     }
     else if (successor != null)
     {
         successor.HandleRequest(request);
     }
     else
     {
         Console.WriteLine("Request for {0} can not be handled", request);
     }
 }
示例#5
0
 public string HandleRequest(int data)
 {
     if (data < this.Limit)
     {
         return("Request for " + data + " handled at level " + id);
     }
     else if (next != null)
     {
         return(next.HandleRequest(data));
     }
     else
     {
         return("Request for " + data + " handled BY DEFAULT at level " + id);
     }
 }
示例#6
0
        static void Main(string[] args)
        {
            Handler start = null;

            for (int i = 5; i > 0; i--)
            {
                Console.WriteLine("Handler " + i + " deals up to a limit of " + i * 1000);
                start = new Handler(i, start);
            }

            int[] a = { 50, 2000, 1500, 10000, 175, 4500 };
            foreach (int i in a)
            {
                Console.WriteLine(start.HandleRequest(i));
            }

            Console.ReadLine();
        }
 //定义一个模板方法,确定责任传递规则,约定一个条件,满足条件时自己处理,否则交给后继者处理。
 public void HandleRequest(int needLevel)
 {
     if (level >= needLevel)     //处理者等级大于等于请求要求的等级时,才可处理
     {
         this.HandleImp();
     }
     else
     {
         if (successor != null)
         {
             //交给后继者处理。
             successor.HandleRequest(needLevel);
         }
         else
         {
             //注意,这里要处理好,无后继者时的情况。
             //如,只好勉强自己处理。
             this.HandleImp();
         }
     }
 }
示例#8
0
 public void HandleRequest(Request request)
 {
     RequestChain.HandleRequest(request);
 }