O'Reilly logo

Object–Oriented Programming with Swift 2 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 AbstractAnimal protocol:

public class Animal: AbstractAnimal { public class var numberOfLegs: Int { get { return 0; } } public class var averageNumberOfChildren: Int { get { return 0; } } public class var abilityToFly: Bool { get { return false; } } public var age: Int init(age : Int) { self.age = age print("Animal created") } public class func printALeg() ...

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