From the course: Swift 5: Protocol-Oriented Programming
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Protocol inheritance
From the course: Swift 5: Protocol-Oriented Programming
Protocol inheritance
- [Instructor] A protocol can inherit from one or more protocols and add new requirements on top of the inherited ones. Protocol inheritance is a useful feature that lets us create granular designs. Let's open the projects from exercise files Chapter 1 01 06. Begin and select the protocol inheritance playground. So here's the Taggable protocol. Now, let's assume that we want to add new requirements. Say we need the ability to save instances to the local storage and restore them later on. Also, we need to retrieve the base64 encoded version of the data. We could squeeze in all these requirements into Taggable. Besides its original requirements, Taggable would also specify persistence and base64 encoding related methods and properties. Our protocol would define too many unrelated requirements. That's a bad design decision and goes against the single responsibility principle. We're going to follow a different strategy. We'll…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
What is protocol-oriented programming?2m 15s
-
Introducing the protocol5m 18s
-
Adopting protocols1m 54s
-
Conforming to protocols via extensions3m 38s
-
Understanding polymorphism4m
-
Protocol inheritance3m 41s
-
Adopting multiple protocols5m 50s
-
Protocol extensions3m 23s
-
Challenge: Removing tight coupling3m 13s
-
Solution: Removing tight coupling8m 33s
-
-
-
-
-