Пример #1
0
        static void Main(string[] args)
        {
            List <Woman> womanList = new List <Woman>();
            Random       random    = new Random();

            for (int i = 0; i < 4; i++)
            {
                int    type    = random.Next(0, 3);
                string request = "逛街的请求";

                Woman woman = new Woman(type, request);
                womanList.Add(woman);
            }

            Father  father  = new Father();
            Husband husband = new Husband();
            Son     son     = new Son();

            father.SetNext(husband);
            husband.SetNext(son);

            foreach (Woman women in womanList)
            {
                father.HandleMessage(women);
            }
            Console.ReadKey();
        }
Пример #2
0
 public void HandleMessage(Woman woman)
 {
     if (woman.type == this.level)
     {
         this.Response(woman);
     }
     else
     {
         if (nextHandler != null)
         {
             nextHandler.HandleMessage(woman);
         }
     }
 }
Пример #3
0
 public override void Response(Woman woman)
 {
     Console.WriteLine("作为父亲我已经同意" + woman.Request());
 }
Пример #4
0
 public abstract void Response(Woman woman);