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.
Adopting multiple protocols
From the course: Swift 5: Protocol-Oriented Programming
Adopting multiple protocols
- [Instructor] So far, we've worked with types that adopted a single protocol. With protocol composition we can create types that conform to multiple protocols. Protocol composition is one of the pillars of the protocol oriented programming paradigm. Swift, like many other programming languages doesn't allow multiple inheritance for classes. However, any type can adapt to multiple protocols. Why is this so important? By conforming to multiple protocols, we can ensure that our types implement the requirements they really need. Instead of inheriting unnecessary noise from a class hierarchy, our types can adopt the protocols that are needed for their proper functionality. All right, let's see how it works. You can follow along with me by opening the starter playground project from the exercise files folder. Chapter one, 0107, begin. First, I create a structure called my data. Let's assume that it has to support…
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
-
(Locked)
Introducing the protocol5m 18s
-
(Locked)
Adopting protocols1m 54s
-
(Locked)
Conforming to protocols via extensions3m 38s
-
(Locked)
Understanding polymorphism4m
-
(Locked)
Protocol inheritance3m 41s
-
(Locked)
Adopting multiple protocols5m 50s
-
(Locked)
Protocol extensions3m 23s
-
(Locked)
Challenge: Removing tight coupling3m 13s
-
(Locked)
Solution: Removing tight coupling8m 33s
-
-
-
-
-