O'Reilly logo

Swift 3 ObjectOriented Programming - Second Edition by Gastón C. Hillar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required