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

Protocol inheritance

From the course: Swift 5: Protocol-Oriented Programming

Start my 1-month free trial

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…

Contents