Member-only story

Double Dispatch in Swift

Collaborate together!

Steven Curtis
3 min readMay 9, 2023
Photo by Markus Winkler on Unsplash

Before we start

Difficulty: Beginner | Easy | Normal | Challenging

This article has been developed using Xcode 11.5, and Swift 5.2.4

Prerequisites

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?

Double Dispatch

--

--

No responses yet