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(); }
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...? } }
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..? } }
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 }