We can create instances of the Party<AnimalElement>
class by replacing the AnimalElement
generic type parameter with any type name that conforms to the constraints specified in the declaration of the Party<AnimalElement>
class. So far, we have three concrete classes that implement both the AnimalProtocol
and Equatable
protocols: Dog
, Frog
, and Lion
. Thus, we can use Dog
to create an instance of Party<Dog>
--that is, a Party
instance of Dog
objects. The following code shows the lines that create four instances of the Dog
class: jake
, duke
, lady
, and dakota
. Then, the code creates a Party<Dog>
instance named dogsParty
and passes jake
as the leader
argument to the initializer. This way, we will create a party of dogs, and Jake is the party leader. The code file for the sample is included in the swift_3_oop_chapter_06_03
folder:
var jake = Dog(name: "Jake") var duke = Dog(name: "Duke") var lady = Dog(name...