Python Concise Guide: Novice will learn object-oriented []

python object-oriented important details and concepts, the role of this part is mainly to in-depth understanding of object-oriented. To complete logic, it may be a slight repeat the previous content.


PS Note: Many people learn Python process will encounter a variety of problems to worry about, no one to help answering easy to give up. For this reason small series built a Python full-stack free Q & A skirt: under seven Yiyi nine plays from Pakistan and five (digital homonym) conversion can be found, but not the older drivers have problems to solve, there is also the latest Python Tutorial Project You can get together with each other ,, supervise progress together!

Class Namespace

For we defined a class, the class will be a part of the name space to store properties defined in the class. The class-defined attributes can be divided into static and dynamic properties.

Static Property is defined in class variables, and dynamic properties is a method in the class definition. Before this method is called on attribute argument also has been described.

Static property class is shared by all objects, and dynamic properties of the class (static method) is bound to all objects.

Target namespace

The following definition of an object class is instantiated obtained, there will be a namespace object to hold the object's properties. When we use the object name to call the property, will be the first to find space in the name, can not find the will to find a space in the class name, can not find the will to find the parent class, if they would not find reported abnormal.

Interface classes

"Third-rate companies make products, second-rate brand companies do, given the standard first-class enterprise" believe that this sentence you more or less have heard of.

Here we interfaces, but also to define standards. Such as payment, pay treasure inside, micro-channel payment, ApplePay certainly not such as to achieve exactly the same. If you pay for this, we define an interface, which is a standard to regulate the function is called, will be able to call different types of payment use a unified format.

About scheduled for the interface, we need the help abc module to complete the corresponding function.

 
interface

The above code also interfaces just want to look, in fact, not a subclass implementation of the abstract method which is also no problem, did not achieve the results we want. In fact, python also did not provide an interface related keywords interface, there are a number of interface functions to achieve only a third-party modules to interface concept of imitation.

Abstract class

An abstract class is a special class that can not be instantiated, but may be inherited. Interfaces mentioned above, among the interfaces must be all abstract methods, we thought, if a class is only part of the way is abstract, there are some methods have a complete realization, that this class is an abstract class. An abstract class is actually a concept interposed between classes and interfaces, while having some of the properties of the classes and interfaces for normalization also help. From another perspective, the abstract object class is obtained, and the abstract class is derived from the abstract class.

Diamond inheritance

Classic depth-first principle, and the new class is taking a breadth-first principle.

 
Diamond inheritance

Polymorphism

On the way, remember, python does not support polymorphism.

Then,that’s all,thank you。

Summary Note: Many people learn Python process will encounter a variety of problems to worry about, no one to help answering easy to give up. For this reason small series built a Python full-stack free Q & A skirt: under seven Yiyi nine plays from Pakistan and five (digital homonym) conversion can be found, but not the older drivers have problems to solve, there is also the latest Python Tutorial Project You can get together with each other ,, supervise progress together!

Text and images in this article from the network with their own ideas, only to learn, exchange, not for any commercial purposes, belongs to original author, if any questions, please contact us for treatment.

Guess you like

Origin www.cnblogs.com/chengxuyuanaa/p/12448083.html