Protocol-Oriented Programming in Swift
Protocol-Oriented Programming in Swift
Summary:
Introduction
The book «Protocol-Oriented Programming with Swift» (2015) by Jon Hoffman is one of the first publications dedicated to the protocol-oriented programming (POP) paradigm in the Swift language. Swift was originally designed as a protocol-oriented language, and the author thoroughly explains how to use protocols, extensions, and composition instead of traditional class inheritance. The book will be useful for iOS and macOS developers who want to write more flexible, testable, and reusable code.
What the book is about
The book consists of 10 chapters, each dedicated to a specific aspect of POP. It starts with the basics: what protocols are, how to declare them, and how to conform to them. The author then moves on to more complex topics: protocol extensions, protocol composition, using protocols with generics, and comparing POP with OOP. Special attention is given to practical examples — creating a game engine, working with delegates, and design patterns.
Who this book is for
The book is aimed at developers already familiar with the basics of Swift and with experience building applications for iOS or macOS. It will be challenging for beginners — knowledge of syntax, data types, and basic OOP is assumed. However, for those who want to move from classical inheritance to a more modern approach, the book will be an excellent guide.
What the reader will learn
- Protocol basics: declaration, conformance, required and optional requirements.
- Protocol extensions: adding default implementations, creating flexible APIs.
- Protocol composition: combining multiple protocols into one type.
- Protocols and generics: type constraints, associated types.
- Design patterns: delegate, strategy, adapter via protocols.
- Testing: how protocols simplify unit testing.
- Comparison with OOP: when to choose protocols and when to choose classes.
Strengths
The main advantage of the book is its practical focus. Each concept is backed by code that can be run in Xcode. The author doesn't just explain theory but shows how to apply POP in real projects. The chapters on protocol composition and using protocols with generics are especially valuable — these topics are rarely found in other books. The clear structure is also worth noting: from simple to complex, with repetition of key ideas.
Who it is recommended for
The book will be useful for all iOS developers who want to deepen their understanding of Swift and learn how to design flexible systems. I especially recommend it to those who are tired of inheritance issues (fragile base class, diamond inheritance) and are looking for an alternative. The book will also be helpful for developers transitioning from Objective-C to Swift — POP will help them quickly master the idioms of the new language.
Despite the book being published in 2015, the core concepts of POP remain relevant in modern versions of Swift (5.x). I recommend it as an introduction to protocol-oriented programming.