Design Mode -- structure mode -- decoration mode -- Java

Source: Internet
Author: User

Decorator intentAttachadditional responsibilities to an object dynamically. decorators provide aflexible alternative to subclassing for extending funible ality dynamically adds some functions for a class, which is more flexible than using inheritance interfaces for objects that can have responsibilities added to them dynamically. define the function interface ConcreteComponentdefines an object to which additional responsibilities can be attached for specific implementation of the Deco Function Ratormaintainsa reference to a Component object and defines an interface that conforms toComponent's interface holds the component reference and defines the function interface ConcreteDecoratoradd sresponsibilities to the component. added the Consequence effect for component More flexibility than static inheritance. lots of little objects is more flexible than static inheritance. A design that uses Decorator often results in systems composed of lots of little objects that all look alike. Requires fewer objects. This results in a large number of small objects. Correlation mode • Ad a p t e r mode: D e c o r a t o r mode is different from A d a p t e r mode, because decoration only changes the responsibility of an object without changing its interface, the adapter will give the object a new interface. • Co m p o s I t e mode: decoration can be viewed as a degraded combination of only one component. However, decoration only adds some additional responsibilities to an object-it does not aim at object aggregation. • St r a t e g y mode: You can use a decoration to change the appearance of an object, while the S t r a t e g y mode allows you to change the kernel of an object. This is two ways to change objects. By observing the FileInputStream constructor, JDK-InputStream does not belong to decorator. JDK-Reader Analysis

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.