Пример #1
0
 public static void GiveFood(Mammal mammal)
 {
     for (
         var currentType = mammal.GetType();
         typeof(Mammal).IsAssignableFrom(currentType);
         currentType = currentType.BaseType)
     {
         if (map.ContainsKey(currentType))
         {
             map[currentType](mammal);
             return;
         }
     }
     DefaultGiveFood(mammal);
 }
Пример #2
0
 void feed(Mammal mammal)
 {
     Feeder.GiveFood(mammal);
 }
Пример #3
0
 public static void DefaultGiveFood(Mammal mammal)
 {
     Console.WriteLine("Feeding an unknown mammal.");
 }
Пример #4
0
 public static void Eat(Mammal animal)
 {
     animal.Eat();
 }
Пример #5
0
 public static void GiveFood(Mammal mammal)
 {
     map[mammal.GetType()](mammal);
 }