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

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