Combining class inheritance with protocol inheritance

So far, we have created many protocols for our animals. Some of these protocols inherit from other protocols; therefore, we have a protocol hierarchy tree. Now, it is time to combine class inheritance with protocol inheritance to recreate our animal classes.

The following lines show the new version of the Animal class that conforms to the AnimalProtocol protocol. The code file for the sample is included in the swift_3_oop_chapter_05_12 folder:

    open class Animal: AnimalProtocol { open class var numberOfLegs: Int { get { return 0; } } open class var averageNumberOfChildren: Int { get { return 0; } } open class var abilityToFly: Bool { get { return false; } } open var age: Int init(age : Int) ...

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.