Alternatives to Protocols

Section • 4 episodes • 1 hr 53 min

Protocols are powerful for abstraction, but they aren’t the only way to abstract. Turns out that nearly every protocol in Swift can be mechanically transformed into a simple concrete data type. In doing so you can accomplish things that are currently impossible with Swift’s protocols, and you can unlock new forms of composition that are impossible to see with protocols.

Where to go from here

Now that we understand the drawbacks of and alternatives to protocols, it’s time to apply this knowledge to a real-world use case. We will develop a snapshot testing library from first principles using protocol-oriented programming and demonstrate the problems that come with this approach. Then we will scrap the protocols, use simple concrete data types, and discover a whole new world of composition.