1. When do I use a combination of classes?
When there are significant differences between classes, and the smaller classes are the components needed to make up a larger class, the combination of classes is more reasonable.
Scene: The hospital is composed of a number of departments, at this time we can define different sections of the class, so that the hospital class we can directly use the different sections of the class to be combined;
2. When do I use the inheritance of classes?
When there are very similar functions between classes, we can extract these common functions into a base class, other classes call the base class directly, and the inheritance of the class is reasonable.
Scenario: Hospitals have patients, doctors, all belong to people, have meals, sleep, age, gender and other methods or characteristics, so that we can first define the human class (including the above methods and characteristics), then we define the patient class and the Doctor class can be directly heir to this class.
Or it can be understood that we define a basic human class, the class of the patient and the doctor, and then derive their own characteristics and methods on the basis of the human class. This approach can also be called a derivation of a class.
Usage scenarios for Python_ class combinations and class inheritance