Decorator mode in Design Mode

Source: Internet
Author: User

Modifier mode: dynamically attaches the responsibility to the object. If you want to extend the function, the modifier provides another option that is different from inheritance.

Principles: (5) open to extensions and disable modifications

Key points: (1) inheritance is one of the extension forms, but it is not necessarily the best way to achieve elastic design.

(2) In our design, we should allow behavior extension without having to modify the existing code.

(3) combination and delegation can be used to dynamically add new behaviors during runtime

(4) Apart from inheritance, the modifier mode also allows us to expand our behavior.

(5) The decorator Mode means a group of decorator classes which are used to package specific components.

(6) The decorator class reflects the type of the component of the decorator.

(7) The decorator Can add his/her own behaviors before/or after the actions of the decorator, and even replace the actions of the decorator for a specific purpose.

(8) You can package a component with countless decorators.

(9) The decorator is generally transparent to the customer of the component, unless the customer program depends on the specific type of the component

(10) The decorator will lead to many small objects in the design. Excessive use will complicate the program.

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.