Swift Object ModelLesson 28Free preview
Swift Polymorphism
This lesson is part of Swift · All levels
Summary
This lesson reviews the concept of polymorphism in Swift where objects from different subclasses can be treated as the same type of superclass. With dynamic dispatch, Swift calls for the implementation of the correct method according to the original instance type at runtime. This concept makes modular and extensible code design easier.
Key points
- Polymorphism allows the manipulation of various derivative objects through a common interface type or superclass
- Dynamic Dispatch ensures that the method being executed is a specific method belonging to the actual instance
- Supports safe casting types 'as?' and 'is' to check the concrete object type
- Can be applied through traditional class inheritance or through Protocol-Oriented Programming
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.