Implementing the bridge pattern

To demonstrate how to use the bridge pattern, we will create two features. The first feature is a message feature that will store and prepare a message that will be sent out. The second feature is the sender feature that will send the message through a specific channel such as email or SMS messaging.

Let's start off by creating two protocols named Message and Sender. The Message protocol will define the requirements for types that are used to create messages. The Sender protocol will be used to define the requirements for types that are used to send the messages through the specific channels. The following code shows how we would define these two protocols:

protocol Message { var messageString: String {get ...

Get Swift 4 Protocol-Oriented Programming - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.