Working with generics in C#

We will create an IAnimal interface to specify the requirements that a type must meet in order to be considered an animal. We will create the Animal abstract base class that implements this interface. Then, we will specialize this class in two subclasses: Dog and Frog. Later, we will create the Party class that will be able to work with instances of any class that implements the IAnimal interface through generics. We will work with the party of dogs and frogs.

Now, we will create an IDeeJay interface and implement it in a HorseDeeJay class. We will also create a subclass of the Party class named PartyWithDeeJay that will use generics to work with instances of any type that implement the IAnimal interface and instances ...

Get Learning Object-Oriented Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.