Chapter 6. Maximization of Code Reuse with Generic Code

In this chapter, you will learn about parametric polymorphism and how Swift implements this object-oriented concept through the possibility of writing generic code. We will use classes that work with one and two constrained generic types.

In addition, you will learn to combine the generic code with inheritance and multiple inheritance to demonstrate the usage of generic code in real-life situations, in which the code becomes more complex than the usage of a simple generic class.

Understanding parametric polymorphism and generic code

Let's imagine we want to organize a party for specific animals. We don't want to mix cats with dogs because the party would end up with the dogs chasing cats. We ...

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.