Declaring subclasses that inherit the conformance to protocols
We have an Animal
class that conforms to both the AnimalProtocol
and Equatable
protocols. Now, we will create a subclass of Animal
, a Dog
class, which overrides the string computed properties defined in the Animal
class to provide the appropriate values for a dog. The code file for the sample is included in the swift_3_oop_chapter_06_03
folder:
open class Dog: Animal { open override var spelledSound1: String { get { return "Woof" } } open override var spelledSound2: String { get { return "Wooooof" } } open override var spelledSound3: String { get { return "Grr" } } open override var danceCharacters: String { get { return "/-\\ \\-\\ /-/" } } }
With just a few additional lines of ...
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.