- Multiple inheritance: (Implements the function of the parent class by inheriting subclasses)
Animal may have different classifications:
Animal------Mammal
------Bird
Animal------Run
------Fly
For each animal dog,cat, parrot may be the first category, or it may inherit the second classification at the same time. The dumb way is to define Runmammal,flymammal,flybird. But when more classifications are needed, it is obviously unreasonable. ------Multiple Inheritance
First, the main class level
class Animal (object): Pass class mammal (Animal): Pass class Bird (Animal): Pass
Then, design the function class:
class Run (object): def Run (self): Print ('Running') class Fly (object): def Fly (self): Print ('Flying')
Finally, the subclass:
class Dog (mammal,run): Pass
This enables multiple inheritance, a design method called Mixin.
Python Multiple inheritance