Member-only story
Double Dispatch in Swift
Collaborate together!
3 min readMay 9, 2023
Before we start
Difficulty: Beginner | Easy | Normal | Challenging
This article has been developed using Xcode 11.5, and Swift 5.2.4
Prerequisites
- You will be expected to be aware how to make a Single View Application in Swift.
- It would be useful to understand something about Polymorphism) in Swift.
- You should be aware of the types of method dispatch in Swift
Terminology:
Double Dispatch: A mechanism that dispatches a function call to different concrete functions depending on the runtime types of two objects involved in the call
Polymorphism: This is the ability of an object to take on many forms, with a common using being a parent class reference to refer to a child class object
Introduction
Double Dispatch is a technique used to invoke an overload method where parameters vary among an inheritance hierarchy.
The Visitor Pattern is built upon the double dispatch principle. So what is it?