top of page
pop.jpeg

Protocol Oriented Programming

Protocol-oriented programming is an incredibly powerful concept which is at the heart of Swift's design. Swift's standard library was developed using protocol oriented techniques, generics, and first-class value semantics; therefore, it is important for every Swift developer to understand these core concepts and take advantage of them. The fourth edition of this book is improved and updated to the latest version of the Swift programming language.

​

This book will help you understand what protocol-oriented programming is all about and how it is different from other programming paradigms such as object-oriented programming. This book covers topics such as generics, Copy-On-Write, extensions, and of course protocols. It also demonstrates how to use protocol-oriented programming techniques via real-world use cases. 

By the end of this book, you will know how to use protocol-oriented programming techniques to build powerful and practical applications.

 

What you will learn
  • Learn the differences between object-oriented programming and protocol-oriented programming

  • Understand why value types should be prioritized over reference types

  • Delve into protocols, protocol inheritance, protocol composition, and protocol extensions

  • Learn how to implement COW (Copy-On-Write) within your custom value types

  • Understand how memory management works in Swift and how to avoid common pitfalls

  • Design applications by starting with the protocol rather than the implementation

 

Who this book is for

This book is intended for Swift developers who have, a good understanding of the Swift programming language and would like to understand how they can use Protocol-Oriented techniques in their applications.

​

Table of Contents
  1. Starting with the Protocol - This chapter will be all about the protocol.  We will show the advantages of using protocols and why we should always think about the protocol first.   We will look at protocol inheritance, composition and polymorphism with protocols.  

  2. Our Type Choices - In this chapter we will discuss the different types that Swift offers (Structs, Classes, Enums and Tuples).  We will show several examples of when to use the various types and when not too.  We will also show the reader what pitfalls to avoid. We wil also look at the types used in the Swift standard library and discuss the advantages of reference vs value types.

  3. Extensions - This chapter will be all about the extensions and protocol extensions and how we can use them to make very flexible and easy to manage code.  We will also look at how extensions are used in the Swift standard library while implementing the equitable protocol using extensions.  

  4. Generics - This chapter will explain how Swift implements generics. Generics allow us to write very flexible and reusable code that avoids duplication.  We will see how Generics are used in the Swift standard library specifically with collection type

  5. Memory Management - This chapter will how Automatic Reference Counting (ARC) works, how much faster value types are as compared to reference types, strong retain cycles, weak vs strong references.  We will also look at how to implement Copy-on-Write in our custom value types

  6. Object-Oriented Programming - This chapter will look at how we would design characters for a game in an Object-Oriented way.  This will give the reader an understanding of the differences between OOP and POP.  We will also look at the drawbacks of Object-Oriented design.

  7. Protocol-Oriented Programming - In this chapter we will create the same characters for a game that we designed in the last chapter but in a Protocol-Oriented way.  This will show the differences between object-oriented programming and protocol-oriented programming so the reader will understand the differences.  By the end of the chapter the reader should have a good working understanding of protocol-oriented programming and what it offers.  We will also show how Apple uses POP is used in the Swift standard library.

  8. Adopting Design Patterns in Swift - This chapter will show you how to implement some of the more common design patterns in Swift in a protocol oriented way. A design pattern identifies a common software development problem and provides a strategy for dealing with it.

  9. Case Studies - In this chapter we will explore two case studies and show how protocol oriented techniques can be used to implement the requirements

​

You can purchase this book on Amazon here.

​

I am always looking for ways to improve the next edition of the Mastering Swift series.  If you have any ideas or suggestions please place a comment on this page or use the contact page to contact me directly. 

bottom of page