Head First Design pattern reading notes (3) Decorator mode

Source: Internet
Author: User
Head First Design pattern reading notes (3) Decorator pattern decorator mode Decorator pattern class diagram

Definition

Decorator mode: By allowing the component class to implement the same interface as the decorator class, the adornment class can dynamically expand the new functionality of the component class without modifying the original component class, and can expand indefinitely.

Some of the original test of OO
  1. Class should be closed for modification, open for expansion. –> "Open and close principle", that is, try not to modify the already used classes, and through the way of inheritance to expand the new functions of the class.
  2. When designing a class, you should consider not modifying the original code as much as possible. –> "Open and closed principle"
  3. The way you combine and broker is often used to dynamically add new features at run time.
about decorator mode
  1. Decorator mode each new feature will reseal a decorator class, which can lead to the "class explosion" problem, the code will have a lot of similar structure of the class, for the first contact with the person is not good understanding and maintenance.
  2. The Decorator class is a mirror of the component class it decorates, with all the functionality of the original component and new functionality.
  3. If the adorner class has the same function signature method as the component class, in this method, the decorator adds new processing logic before/after calling the component method to add new functionality to the component.
  4. The input and output stream related classes in Java are implemented through decorator pattern.

Head First Design pattern reading notes (3) Decorator 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.