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 instances of any class that conforms to the AnimalProtocol
protocol through generics. We will work with a party of dogs, one of frogs, and another 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
that will use generics to work with instances of any type that conforms to the AnimalProtoocol
protocol and instances of any type that conforms to the DeeJaypProtocol
interface. We will work with a party of dogs with a DJ.