"Design Mode Design Pattern" Read Nine Notes
Decorator mode
structure
purpose
Dynamically add a function of responibilities.
discuss
1. Give an object to increase the function, the easiest way is to derive a class; but this is a static method, not flexible.
And Decorator is a dynamic approach, more flexible.
2, for a lightweight Component, Decorator mode is a better way, but if Component is heavy, Decorator will cost too much. For weight, Strategy mode can be taken.
The Decorator is like a layer of coat to Component, and Component does not need to know what is put on it. And Strategy is the interior of the company, maintaining a new functional object within internal maintenance.
3, Decorator can be seen as a special composite, which is only a Component's Composite; but the purpose of Decorator is to increase additional features, and Composite's purpose is to integrate objects.
Reference
"Design Pattern" Gang-Of-4 1997