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 InsertBirds(ICollectionSet <Bird> birds)
        {
            for (int index = 0; index < 5; index++)
            {
                Bird b = new Bird("Tweety");
                b.FlapWings();
                birds.Set(b);

                Cat c = new Cat("Spot");
                c.Purr();
                // birds.SetAnimal(c); // Why does this NOT work...?
            }
        }
Example #3
0
        public void InsertAnimals(ICollectionSet <Animal> animals)
        {
            for (int index = 0; index < 5; index++)
            {
                Bird b = new Bird("Tweety");
                b.FlapWings();
                animals.Set(b); // Why does this work..?

                Cat c = new Cat("Spot");
                c.Purr();
                animals.Set(c); // 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
        }