Design Pattern---decoration mode

Source: Internet
Author: User

    Decorating mode: Dynamically adds some additional responsibilities to an object, and the adornment mode is more flexible than generating subclasses for added functionality.

  If there is only one concretecomponent class and no abstract component class, then the decorator class can be a subclass of Concretecomponent. Similarly, if there is only one Concretedecorator class, then there is no need to create a separate decorator class, and you can combine the responsibilities of decorator and Concretedecorator into a single class.

    Summary: When the system needs new functionality, it is adding new code to the old class. These new codes often adorn the core responsibilities or main behaviors of the original class. They add new fields, new methods, and new logic to the main class, increasing the complexity of the main class. And these new things are just to meet the needs of some particular behavior that will only be performed in certain circumstances.

Decoration mode provides a great solution, which puts each function to be decorated in a separate class, and lets the class wrap the object it is decorating, so that when special behavior is required, the customer code can selectively and sequentially use the adornment function to wrap the object at run time.

Design Pattern---decoration mode

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.