Python Learning note 012--decorator

Source: Internet
Author: User
1 Adorner 1.1 Adorner definition

A way to dynamically add functionality during code runs, called an "adorner" (Decorator).

1.2 Decorator Categories

Decorators: function Decorators, class decorators, function decorators, class decorators

adorners: function decoration function, function adornment class, class adornment function, class adornment class (the two are not one by one correspondence, actually I do not know what kind of correspondence between them)

In general, the main application is function decoration function

1.3 Adorner nature

Essentially,decorator is a higher-order function that returns a function .

In the object-oriented (OOP) design pattern, the decorator is called the adornment mode. The decorative patterns of OOP need to be implemented by inheritance and composition ,

In addition to supporting OOP decorator, Python supports decorator directly from the syntax level.

Python's decorator can be implemented using functions or classes.

1.4 Adorner Purpose

Enrich the functionality of the original object without changing the name of the object

1.5

Python Learning note 012--decorator

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.