The decoration mode (decorator) is also called the wrapper mode (wrapper). The idea of "decorating" vividly depicts the intention to "dynamically add some additional responsibilities" to an object. Gof's definition in design mode is: Dynamically adding additional responsibilities to an object. The decorative mode makes full use of the advantages of inheritance and aggregation, and creates the design aesthetics of no and ratio. Decorator mode is more flexible than generating subclasses in terms of adding functionality.
UML diagram:
I. Motivation to use the decorator model
Now there is a scenario that requires us to dynamically add new responsibilities to an object that does not modify the original behavior, but instead adds new functionality based on the original behavior, just as we do with fresh and tasty tomato juice when eating french fries.
From an object-oriented perspective, we have to add a new responsibility for an object that can be implemented using inheritance mechanisms, but such a design can lead to the problem of "overly using inheritance to extend the functionality of objects" because of the static nature introduced by inheritance, which makes this extension inflexible; and as word classes grow, (expanded functionality), the combination of seed classes (the combination of extended functions) can cause more subclasses to swell, known as class explosions. How can the extension of object functionality be dynamically implemented as needed while avoiding the explosion of "extended functionality"? So that any "functional expansion changes" will result in the lowest impact?