Adapter Design Pattern in Swift

Kelvin Tan
Swiftly Engineered iOS
5 min readOct 24, 2023

--

Photo by Call Me Fred on Unsplash

The Adapter design pattern is a structural design pattern that allows objects with incompatible interfaces to collaborate. The pattern enables the conversion of the interface of an existing class to the interface expected by the client class. This allows the client class to use the existing class without changing its code.

In this article, we will explore the Adapter design pattern with an example in Swift.

The Adapter Design Pattern

The Adapter design pattern is one of the structural design patterns. Structural patterns are concerned with the composition of classes and objects to form larger structures. The Adapter pattern provides a way to connect two incompatible interfaces, allowing them to work together.

In the Adapter pattern, there are three main components:

  1. Client: The class or object that requires a specific interface to work with.
  2. Adaptee: The class or object with an incompatible interface that needs to be adapted to work with the client.
  3. Adapter: The class that adapts the interface of the Adaptee to the interface expected by the Client.

The Adapter pattern is often used to make legacy code work with new code or to integrate third-party code into an existing system.

--

--

Kelvin Tan
Swiftly Engineered iOS

Father, husband, software engineer. Building software and building a family, one line of code and one moment at a time. 🚀💻💙 http://ko-fi.com/kelvintanzy