Chapter 5. Contract Programming with Protocols

In this chapter, we will work with more complex scenarios in which we will have to use instances that belong to more than one blueprint. We will use contract programming by taking advantage of protocols.

We will work with examples on how to define protocols and their different kinds of requirements, and then on how to declare classes that adopt the protocols. We will use multiple inheritance of protocols and many useful ways of taking advantage of this object-oriented concept, also known as interfaces in other programming languages such as Java and C#.

Understanding how protocols work in combination with classes

We have to work with two different types of characters: comic and game characters. A comic ...

Get Swift 3 ObjectOriented Programming - Second 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.