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 O’Reilly online learning.

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