Beispiel #1
0
 // 事件由下往上传递
 public virtual void onKeyEvent(KeyEvent keyEvent)
 {
     if (this.Parent != null)
     {
         this.Parent.onKeyEvent(keyEvent);
     }
     else
     {
         Console.WriteLine("All not process!");
     }
 }
Beispiel #2
0
 public override void onKeyEvent(KeyEvent keyEvent)
 {
     if (keyEvent.Type == Event.EEventType.LISTEN)
     {
         Console.WriteLine(this.ToString() + " command over!");
     }
     else
     {
         Console.WriteLine(this.ToString() + " not process!");
         base.onKeyEvent(keyEvent);
     }
 }
Beispiel #3
0
        static void test_responsibility_mode()
        {
            /*
             * 责任链模式:将请求的发送者和接收者之间解耦,使多个对象都有机会处理这个请求。
             * 将这些对象连成一条链,并沿着这条链传递该请求,直到有一个对象处理它。
             */
            Console.WriteLine("\n---------------- test responsibility --------------------\n");
            KeyEvent keyEvent = new KeyEvent(Event.EEventType.READ);
            SystemEvent systemEvent = new SystemEvent(Event.EEventType.READ);
            Processor processor_a = new ProcessorA(null);
            Processor processor_b = new ProcessorB(processor_a);
            Processor processor_c = new ProcessorC(processor_b);
            Processor processor_d = new ProcessorD(processor_c);

            Console.WriteLine("\n---- from top to bottom\n");
            processor_a.onSystemEvent(systemEvent);
            Console.WriteLine("\n---- from bottom to top\n");
            processor_d.onKeyEvent(keyEvent);
        }