inherit:
What is inherited:
Inheritance is a relationship, what is the relationship between the description of what the two objects
In the program, describes the inheritance relationships between classes and class
E.g. inherited a b, a b can be used directly in existing methods and properties of
called a subclass, b is called the parent class, referred to as the base class or superclass
Why use inheritance:
Inheritance can be used directly by one of the party has inherited some things, which are designed to reuse existing code to enhance the reusability of the code
How to use inheritance:
class class name (the name of the parent class): the contents of the class # a sub-class in python can inherit multiple parent classes at the same time
Abstract: not specific, unclear, vague, look do not understand
The process of the same parts of the plurality of subclasses, extraction, to form a new class, a process also known as abstract
The proper use of inheritance:
1, the first abstract inheritance
2, inherit a class that has been achieved, extend or modify the original function
Find the order of attributes: the object itself -> where the class -> find parent -> Object
Derived: When a subclass of a parent class appears in different content, this subclass is also known as a derived class, subclass generally will write some new code, and the parent can not be exactly the same. So generally refers to a derived class is a subclass
Cover: also known overrides
When the sub-category appear entirely consistent with the name of the parent class property or method
Subclass access the parent class Content:
Mode. 1: Super (current class name, self) you want to adjust the properties or methods of the parent class. Manner 2: Super () you want to adjust the properties or methods of the parent class. Embodiment 3: the name that you want to transfer the parent. class property or method (Self) # manner regardless of the inheritance 3
He stressed: When a inherit an existing class, and you override the ancestor __init__ method, you must initialize method in the first line calls the parent class initialization method, the parent than the incoming parameters needed .
Combination: a relationship, what is the relationship between what is described in two objects
Objective combinations: a combination of inheritance as compared to the greatly reduced coupling
Improve code reusability
When to use inheritance: analysis of the relationship between two classes, in the end is not: What is the relationship between what
When to use a combination of: if there is no significant relationship between the two classes, do not belong to the same
Diamond inheritance: python supports multiple inheritance
The new class: any display or implicit Object classes are inherited from the new class is called, python3 in all new class
Classic: Object subclass that is not only appear in the python2
When there is diamond inheritance: The first depth when faced with a common parent class on breadth
Classic is the depth-first