Decorator mode
Name: Decorative mode, packaging mode (WAPPER)
problem:
You need to extend a class of features, or add additional responsibilities to all kinds; you need to dynamically give an object increase function, which may be dynamically revoked; need to increase the alignment combination of basic functions to generate a very large function, so that the inheritance relationship is not reality.
E.g:
A graphical interface toolbox allows you to add some features (such as borders such as borders), inheritance, but, hypothesis, it is obvious that we cannot add that multi-characterity.
solve:
The components are embedded in another object, and the borders such as the object are added, and this embedded object is decorated, which is the same as the component interface he decorated, so it is transparent to the user who uses it. This decorative object requests the interface method to the component, and has the opportunity to perform related "decoration" operations before and after forwarding, and you can allow you to recurrent nested decoration to achieve more features.
effect:
Dynamically, any expansion of component letter feature, and can be increased any recursive call. Can handle "revocation" responsibilities. Customers will not feel the difference between decoration, nor does any dependence on the decoration.
Photo:
Facede mode
Name: Facade mode, appearance mode
problem:
Suppose a programming environment, contains multiple subclasses, such as Scanner, ProgramNode ..., etc. to implement compilation environments. However, for most of the user's tasks, users don't care about compilation, and subclasses in the compilation environment will only make users feel complicated.
solve:
Add a Complier class to define and implement a compiler unified interface, you can combine a system interface that you can use by the user without hiding a class that implements detail. This CompliRer class is actually the facade of the compilation subsystem (note that these subclasses are not required to be completely hidden).
effect:
You can block the subsystem to reduce the burden on the customer. A loose coupling with the subsystem is realized. However, if the system needs, the subsystem's request is not limited.
Photo: