O'Reilly logo

Learning Object-Oriented Programming 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

Working with duck typing in Python

We will use the Animal base class to generalize the requirements for animals. First, we will specialize the base class in two subclasses: Dog and Frog. Then, we will create a Party class that will be able to work with instances of any Animal subclass through duck typing. We will work with a party of dogs and a party of frogs.

Then, we will create a HorseDeeJay class and generate a subclass of the Party class named PartyWithDeeJay. The new subclass will work with instances of any Animal subclass and any instance that provides the properties and methods declared in the HorseDeeJay class through duck typing. We will work with the party of dogs with a DJ.

Declaring a base class that defines the generic behavior

We will ...

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