Java Design Patterns

Source: Internet
Author: User
Decorative (Decorator) design pattern
  • Dynamically adding some extra functionality to an object, the decorative pattern is more flexible than generating subclasses for added functionality
  • The ability to dynamically extend an object without changing the original class file and using inheritance (this is the benefit of the decorative design pattern)
  • The decorative design pattern is to create a wrapper object that uses decorations to wrap real objects.

Application Scenarios:

  • Need to extend the functionality of a class, or add additional responsibilities to a class
  • When it is not possible to implement by generating subclasses, for example, the final class

How to implement the decoration mode:

  • Decorative objects and real objects have the same interface
  • A decorative object contains a reference to a real object
  • All methods of decorating objects, internal implementations are invoked through references to real objects, and then implement their own functions,

Java Design Patterns

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.