Design design Pattern C # language Description--decoration (decorator) mode
* This article refers to "Java and the pattern" part of the content, suitable for the design pattern of beginners.
The decorative pattern, also known as the wrapper pattern, extends the function of the object transparently to the client, and is an alternative to the inheritance relationship. It uses an instance of a subclass of the previously decorated class to delegate the client's invocation to the decorated class, and the client does not feel that the object is different before and after the decoration. You should use decorative mode when you need to extend the functionality of a class or add additional responsibility to a class. Dynamically adding functionality to an object, these functions can be undone dynamically. The need to increase the number of functions generated by the permutations of some basic functions makes the inheritance relationship impractical.
The class diagram looks like this:
The decoration mode includes the following roles:
Abstract widget (Component): gives an abstract interface to the specification of the object to receive additional responsibility.
Concrete Widget (Concrete Component): Defines a class that will receive additional responsibility.
Decoration (decorator): Holds an instance of a Component object and defines an interface that is consistent with an abstract component interface.
Concrete Decoration (concrete decorator): Responsible for "affixed" to the Component Object "additional responsibility".
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.