The main topic of this lesson
- Object-oriented polymorphism
- Object-oriented Members
- Member modifiers
- Special members
- Object-oriented other applications
- SOURCE extension
- Exception handling
- Design Patterns and Singleton patterns
Object-oriented polymorphism
To a member of an object
Normal fields are saved in the object, static fields are saved in the class.
For a static field, as long as the load is created in memory, the static method is called by you, the object is used to encapsulate the data, and if you want to encapsulate the data, create the object. It is not necessary to create objects without objects, because the adjustment of the meditation method is not dependent on any of the images, which saves the space. static method = function of Python.
Python has three methods
- Common methods
- static method, it is used for the use of the type, is not to turn anything on the line
- Class method, which, when it is written, must pass in the class parameter, and it will pass the class into the method itself.
Object-oriented properties
Only pseudo-field access form, it only provides an associative way
- The program is executed with parentheses, e.g. Obj.func (), Access to the field Obj.name, after the use of the property can be executed when the method without parentheses, e.g. Obj.func, this setting, the object can only get (Getter function) Its return value can not be modified or re-assigned to this method,
- If you want to assign a value to an attribute class, you must add a method.setter adorner (setter function), e.g. @all_page. Setter;
- If you want to delete a sexual value, you can add a method.deleter adorner (delete function), e.g. @all_page. deleter.
Member modifiers
Special members
__DICT__: Getting the data in the object
__STR__:
__GETITEM__: If the obj[' a ' is executed by obj[1:5], it will automatically execute the __getitem__ method, take the values based on the index and take the values based on the slices, they return the same type.
__SETITEM__: If you execute obj[' a ']=111, it will automatically execute the __setitem__ method.
__DELITEM__: If you execute del obj[' a '], it will automatically execute the __delitem__ method.
__CALL__: If you execute obj (), it will automatically execute the __call__ method.
Object-oriented other applications
Executes methods of the parent class, actively executes methods of the parent class
>>> class C1: ... def F1 (self): ... print ( " ' ' ... >>> class C2 (C1): ... def F1 (self): ... super (c2,self). F1 () ... print ( " ' ' ... >>> obj=c2 () >>> Obj.f1 () C1.F1C2.F1
View Code
Ordered dictionaries
SOURCE extension
Exception handling
List of Exception errors
Indexerror
ValueError
Design Patterns and Singleton patterns
Singleton mode with a total of 23 design modes
What is a singleton mode: an example, an instance, that is, it has only one object, which is primarily used to create a single instance. The following is an example of a database connection pool
Eighth: Python-based object-oriented (episode)