static void Main(string[] args) { IAnimalCollection <IAnimal> animalCollection = GetDogCollection(); //animalCollection.AddAnimal(new Cat()); //Would get a compiler error because this method no longer exists. }
public AnimalService(IAnimalCollection collection) { _collection = collection; }
static void Main(string[] args) { IAnimalCollection <IAnimal> animalCollection = GetDogCollection(); animalCollection.AddAnimal(new Cat()); //We just added a cat to a collection of dogs. }
static void Main(string[] args) { IAnimalCollection <IAnimal> animalCollection = GetDogCollection(); //animalCollection.AddAnimal(new Cat()); //Would get a compiler error if we tried to add a cat to the collection }