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