Using a generic class with two generic type parameters

We can create instances of the PartyWithDeeJay<AnimalElement, DeeJayElement> class by replacing both the AnimalElement and DeeJayElement generic type parameters with any type names that conform to the constraints specified in the declaration of the PartyWithDeeJay<AnimalElement, DeeJayElement> class. We have three concrete classes that implement both the AnimalProtocol and Equatable protocols: Dog, Frog, and Lion. We have one class that conforms to the DeeJayProtocol protocol: HorseDeeJay. Thus, we can use Dog and HorseDeeJay to create an instance of PartyWithDeeJay<Dog, HorseDeeJay>. The following lines create a HorseDeeJay instance named silver. Then, the code creates a PartyWithDeeJay<Dog, ...

Get Swift 3 ObjectOriented Programming - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.