Discover that Swift does not allow multiple inheritance for classes, yet with protocol composition, Swift types can adopt multiple protocols.
- [Instructor] Protocol composition is one of the pillars…of the protocol-oriented programming paradigms.…Swift doesn't allow multiple inheritance for classes.…But with protocol composition,…Swift types can adopt multiple protocols.…Why is this so important?…By conforming to multiple protocols,…we can ensure our types only implement…the requirements they really need.…Instead of inheriting unnecessary noise…from a class hierarchy,…our types will only adopt the protocols…they need for their proper functionality.…
Let's demonstrate how protocol composition works.…So far, we've been using types…that adopted either one or another protocol.…With protocol composition,…we can create types that conform…to multiple protocols.…For example, what if we need a struct,…let's call it simply MyData,…that provides support for persistence…and base64 encoding.…All we need to do is make it adopt…both the BinaryPersistable…and Base64Encodable protocol.…
So let's adopt the Base64Encodable…and the BinaryPersistable…protocol.…Now this code won't compile,…
- Comparing object-oriented programming with protocol-oriented programming
- Methods and class-bound protocols
- Adopting a protocol
- Declaring asynchronous behavior
- Preparing and implementing fallback logic
- Implementing an app using protocol-oriented programming
Skill Level Intermediate
1. Protocol-Oriented Programming
4. Implement the Weather App Using POP
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.