Python Random Notes

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.