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

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

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