1.AOP
The same code and repetitive functions are extracted from the inside of different classes to be reused.
The adorner is a well-known design pattern, which is often used for scenes with cut-off requirements, more classic insert logs, performance testing, transaction processing, etc.
2. New class, Classic class
The new class inherits the built-in object objects (or from built-in types such as list,dict, etc.) while the classic class is directly declared.
3.__metaclass__类创建,__new__实例创建,__init__实例初始化
4.python Single-Case mode
A class creates an object instance by invoking the __new__ (CLS) method of the parent class object to create the object, and we can implement the class by overriding the __new__ (CLS) method to create only one instance
Class Singleton (object):
__instance = None
def __init__ (self):
Pass
Def __new__ (CLS, *args, **kwargs):
if cls.__instance = = None:
Cls.__instance = object.__new__ (Cls,*args,**kwargs)
Return cls.__instance
A=singleton ()
B=singleton ()
Print (a)
Print (b)
Python Random Notes