Image example:
Mary should not ask her to pick her up after her birthday. Otherwise, the food expenses for this month will surely be finished. She took out the photo I took on the top of Huashan last year and wrote "the best gift" on the back, I love your FITA. "I went to the gift shop on the street and bought an image frame (the mm for selling gifts is also very beautiful ), mike, who is next door to art design, designed a beautiful box and installed it ......, We are all decorator, and we are all modifying this person. How do you understand this?
Decoration mode:
The decoration mode extends the object functions in a transparent way to the client. It is an alternative to the inheritance relationship and provides more flexibility than inheritance. Dynamically adds features to an object, which can be dynamically revoked. A large number of functions are generated by the arrangement and combination of some basic functions.
Purpose:
Dynamically add some additional responsibilities to an object. The decorator mode is more flexible than the subclass generation function.
UML structure diagram:
Abstract base class:
1) component: defines an object interface, which can dynamically add responsibilities to this interface.
2) decorator: maintains a pointer to component and has an interface function consistent with component.
Interface functions:
1) component: Operation: this interface function is declared by component. Therefore, all the derived classes of component must be implemented. You can dynamically add responsibilities to this interface function.
Resolution:
The derived class of the decorator can dynamically add roles to the objects of the concreatecomponent class, or you can say that the derived class of the decorator is decorated with objects of the concreatecomponent class. specifically, initialize a concreatecomponent Class Object (decorator) and use this object to generate a decorator object (decorator ), the subsequent call to the operation function is a multi-state call to the member function of the decorator object. the main point of implementation here is that both the decorator class and the concreatecomponent class inherit from component, so that the interface functions of both are consistent. Secondly, decorator maintains a pointer to component, this allows you to call the component: operation function dynamically.
Design Pattern _ decorator _ decoration pattern