static void Main(string[] args)
        {
            // No problem, since Collection implements
            // ICollectionGet and ICollectionSet
            Collection <Bird>     birds    = new Collection <Bird>();
            ICollectionGet <Bird> birdsGet = birds;
            ICollectionSet <Bird> birdsSet = birds;

            // No problem, since Collection implements
            // ICollectionGet and ICollectionSet
            Collection <Animal>     animals    = new Collection <Animal>();
            ICollectionGet <Animal> animalsGet = animals;
            ICollectionSet <Animal> animalsSet = animals;


            AnimalProcessor processor = new AnimalProcessor();

            // How many of these work...?
            //
            //processor.ProcessAnimals(birdsGet);   // Case A
            //processor.ProcessAnimals(animalsGet); // Case B

            //processor.ProcessBirds(birdsGet);     // Case C
            //processor.ProcessBirds(animalsGet);   // Case D

            //processor.InsertAnimals(birdsSet);    // Case E
            //processor.InsertAnimals(animalsSet);  // Case F

            //processor.InsertBirds(birdsSet);      // Case G
            //processor.InsertBirds(animalsSet);    // Case H

            KeepConsoleWindowOpen();
        }
Example #2
0
 public void ProcessAnimals(ICollectionGet <Animal> animals)
 {
     for (int index = 0; index < animals.Count; index++)
     {
         Console.WriteLine(animals.Get(index).Sound());
         // animals.GetAnimal(index).FlapWings(); // Why does this NOT work...?
     }
 }
Example #3
0
 public void ProcessBirds(ICollectionGet <Bird> birds)
 {
     for (int index = 0; index < birds.Count; index++)
     {
         Console.WriteLine(birds.Get(index).Sound());
         birds.Get(index).FlapWings(); // Why does this work..?
     }
 }
Example #4
0
        private static void VarianceTests()
        {
            // No problem, obviously
            Bird b = new Bird("Olaf");

            Console.WriteLine(b.Sound());

            // No problem, since Bird inherits from Animal
            Animal a = new Bird("Piphans");

            Console.WriteLine(a.Sound());

            // No problem, since AnimalCollection implements
            // ICollectionGet and ICollectionSet
            Collection <Bird>     birds    = new Collection <Bird>();
            ICollectionGet <Bird> birdsGet = birds;
            ICollectionSet <Bird> birdsSet = birds;

            // No problem, since AnimalCollection implements
            // ICollectionGet and ICollectionSet
            Collection <Animal>     animals    = new Collection <Animal>();
            ICollectionGet <Animal> animalsGet = animals;
            ICollectionSet <Animal> animalsSet = animals;


            AnimalProcessor processor = new AnimalProcessor();

            // How many of these work...?
            ////
            //processor.ProcessAnimals(birdsGet);   // Case A
            //processor.ProcessAnimals(animalsGet); // Case B

            //processor.ProcessBirds(birdsGet);     // Case C
            //processor.ProcessBirds(animalsGet);   // Case D

            //processor.InsertAnimals(birdsSet);    // Case E
            //processor.InsertAnimals(animalsSet);  // Case F

            //processor.InsertBirds(birdsSet);      // Case G
            //processor.InsertBirds(animalsSet);    // Case H
        }