Example #1
0
        public static void ClientCode(AbstractHandler handler)
        {
            foreach (var food in new List <string> {
                "Nut", "Banana", "Cup of coffee", "Rat"
            })
            {
                Console.WriteLine($"Client: Who wants a {food}?");

                var result = handler.Handle(food);

                if (result != null)
                {
                    Console.Write($"   {result}");
                }
                else
                {
                    Console.WriteLine($"   {food} was left untouched.");
                }
            }
        }
Example #2
0
 public void SetHandler(AbstractHandler handler)
 {
     this.handler = handler;
 }