public static void DoFlyerTest(IFlyer flyer) { flyer.TakeUpper(100); flyer.TakeLower(50); flyer.TakeUpper(100); flyer.TakeLower(100); }
public Animal(string name, IFlyer flyer) { if (string.IsNullOrEmpty(name)) { throw new ArgumentException("Must not be null or empty.", "name"); } if (flyer == null) { throw new ArgumentNullException("flyer"); } Name = name; Flyer = flyer; }
static void Main(string[] args) { List <Animal> animals = new List <Animal>(); Dog d = new Dog(); animals.Add(d); Bird b = new Bird(); animals.Add(b); foreach (Animal animal in animals) { animal.Foo(); //Bird bird = animal as Bird; //if(bird != null) { // Console.WriteLine("The animal can fly"); // MakeFly(bird); // continue; //} //Bat bat = animal as Bat; //if(bat != null) { // Console.WriteLine("The animal can fly"); // MakeFly(bat); // continue; //} IFlyer flyer = animal as IFlyer; if (flyer != null) { Console.WriteLine("The animal can fly"); MakeFly(flyer); continue; } } }
public static string Fly(this IFlyer flyer) { return("I'm flying"); }
static void MakeFly(IFlyer flyer) { flyer.Fly(); }
private static void DoFly(IFlyer flyer) { flyer.Fly(); }
public Bird(string name, IFlyer flyer) : base(name, flyer) { }
public Dog(string name, IFlyer flyer) : base(name, flyer) { }