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); }
void feed(Mammal mammal) { Feeder.GiveFood(mammal); }
public static void DefaultGiveFood(Mammal mammal) { Console.WriteLine("Feeding an unknown mammal."); }
public static void Eat(Mammal animal) { animal.Eat(); }
public static void GiveFood(Mammal mammal) { map[mammal.GetType()](mammal); }