Package Enclosure
Encapsulation refers to the implementation details of a hidden class, which makes it easier for others to call.
Purpose of Encapsulation:
Allows the consumer to manipulate the object by indirectly invoking the method or property.
So when Python uses encapsulation, it must use private properties and methods.
Private properties and methods:
A private member that starts with an ' __ ' double underscore and does not end with a double-declining line
Private members can only use methods of this class to access and modify
1. Properties that begin with __ are private properties such as __vol
2. Methods that begin with __ are private methods such as __vol ()
Note: Python encapsulation is a fake package (analog encapsulation)
For example, through the Dir view properties can be found, in fact, the private property has become _class__xx, so it is not accessible
Polymorphic polymocphic
Literally: ' multiple states '
Polymorphism refers to the method of invoking a base class object in a class that has an inheritance/derivation relationship, and the actual ability to invoke the overlay method of a subclass is called polymorphic
State:
Static (compile-time state)
Dynamic (run-time state)
Description
1, the method of the polymorphic call is related to the object and is not related to the type
2,python all objects have only "runtime State (dynamic)"
No compile-time state (static) in the C + + language
Inherit inheritance
Inheritance is a new class derived from an existing class, with the new class having the data properties and behavior of the original class, and
To develop new behaviors.
Purpose of Inheritance:
Extending the functionality of the old class
Single inheritance
Grammar:
Class name (base class name):
Statement block
Description
Single inheritance refers to a new class derived from a base class
Multiple Inheritance multiple inheritance
Multiple inheritance refers to a subclass that inherits from two or more than two base classes
Grammar:
Class name (base class Name 1, base class Name 2, ...) )
Description
A subclass inherits from multiple fathers at the same time, and the methods of the parent class can be inherited at the same time
If two fathers have a method with the same name, and the method is not overridden in a subclass, the call
The results are difficult to determine
Multiple inheritance issues (defects)
Identifier conflict issues
(It is generally not recommended to use multiple inheritance)
For an example, please take note of the next article
The three main features of Python object-oriented: encapsulation, inheritance, and polymorphism