O'Reilly logo

Swift 3 ObjectOriented Programming - Second Edition by Gastón C. Hillar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required