We will create an AnimalProtocol
protocol to specify the requirements that a type must meet in order to be considered an animal. Then, we will create an Animal
base class that conforms to this protocol, and then, we will specialize this class in three subclasses: Dog
, Frog
, and Lion
. Then, we will create a Party
class that will be able to work with the instances of any class that conforms to the AnimalProtocol
protocol through generics. We will work with a party of dogs, a party of frogs, and a party of lions.
Then, we will create a DeeJayProtocol
protocol and generate a HorseDeeJay
class that conforms to this new protocol. We will create a subclass of the Party
class named PartyWithDeeJay
, which will use generics to work with the instances of any type that conforms to the AnimalProtocol
protocol and the instances of any type that conforms to the DeeJaypProtocol
interface. We will work with a party of dogs with a DJ.