# This is a learning note for the Liaoche teacher Python tutorial
A child class can have more than one parent class. This is called multiple inheritance. with multiple inheritance, a subclass can get all the functionality of multiple parent classes at the same time.
1.1 , M ixin
When you design an inheritance relationship for a class, the main line is usually single-inherited.
add extra functionality to a class through multiple inheritance. This design we call Mixin
definition Mammal class
Class mammal (Object):
Pass
definition runable class
Class Runnable (object):
def run (self):
Print (' Running ... ')
definition Dog class, multiple inheritance
Class Dog (Mammal, Runnable):
Pass
Note:
In order to better see the inheritance relationship, we can change the runnable to Runnablemixin
Only allow single-inherited languages (such as Java) to use the mixin design
1.2 , Mixin Case
Python comes with two types of network services, TCPServer and Udpserver, and a multi-process or multithreaded model must be used to serve multiple users at the same time, both of which are forkingmixin and threadingmixin provided. By combining, we can create the right services to
Writing a TCP service with a multi-process pattern
Class Mytcpserver (TCPServer, forkingmixin):
Pass
Write a multithreaded mode UDP service
Class Myudpserver (Udpserver, ThreadingMixIn):
Pass
Co-process Model
Class Mytcpserver (TCPServer, coroutinemixin):
Pass
Python Learning note __7.3 multiple inheritance