Here is still based on the online information, mainly Liao Xuefeng Teacher's tutorial study notes, the main introduction of Python object-oriented advanced features, notes are not all, just record oneself feel error prone places * * *
1.python as a dynamic language, his dynamic binding mechanism allows to dynamically add methods and properties to class or object instances during the run, which is difficult to do in a static language such as Java;
1) Dynamic binding properties:
2) Dynamic binding method
The method of binding to an instance is not visible to other instances and classes: ( This also shows that the dynamic binding method for an instance must be Methodtype (func, instance))
But the methods that are bound to the class are visible to all instances
2.__slots__ = (' attribute1, Attribute2 ') in order to restrict binding property names to classes, but not for inherited subclasses:
There is no restriction on inherited subclasses:
As long as there is a __slots__ = () statement inside the class, only the object of the class is bound to the property in parentheses and the allowed binding property inherited from the parent class, (there are two types, the parent has slots statements and no slots statements):
The parent class does not have a slots statement, and although the subclass has restrictions, it can still bind other types:
The parent class has the slots statement above already has, does not demonstrate;
3. Multiple Inheritance:
1) Java only allows single re-inheritance, Pyhon allows multiple inheritance, with mixin design implementation;
2) The advantage of mixin is to add multiple functions to the class, have good extensibility, write the function as Xxxmixin class, and inherit the property and method directly.
3) Use mixin not to design multi-layered complex inheritance relations;
Python advanced features for object-oriented programming