Exemple #1
0
        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();
 }
Exemple #6
0
 private static void DoFly(IFlyer flyer)
 {
     flyer.Fly();
 }
Exemple #7
0
 public Bird(string name, IFlyer flyer)
     : base(name, flyer)
 {
 }
Exemple #8
0
 public Dog(string name, IFlyer flyer)
     : base(name, flyer)
 {
 }