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.
Understanding polymorphism
From the course: Swift 5: Protocol-Oriented Programming
Understanding polymorphism
- Polymorphism is a fundamental object oriented programming concept and it's also essential to protocol oriented programming. Polymorphism comes from Greek and means many forms in programming. It denotes the ability to provide a single interface to different types. To illustrate the concept, I went ahead and created a playground project. You can find it in the exercise files for their chapter one or 105 and begin. Let's have a look at the shapes playground. The shape protocol defines the read-only area properly. This is the only property requirement that conforming types must implement. I've created several concrete shapes that conform to the shape protocol, square, rectangle, rhombus, and circle. Now let's define a variable of type shape VAR shape of type shape. We can't instantiate the shape protocol directly. However, we can take advantage of the polymorphic behavior and assign any of the concrete types to the shape…
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
-
-
-
-
-