Decorator mode is concerned with adding features
The focus of the proxy mode is to control the access of the object, whose prototype object is not known to the user
Adapter mode is concerned with adaptation, which is defined as the extension of the core object or function, and the adapter pattern is to put the object or function in a new object reference. For example, now the book selling moral books, there are thread version, there is a hardcover version, there is a Japanese version, there is an English version, of which thread version and hardcover is the decoration mode , the Japanese version and the English version is the adapter mode , various versions are to cater to different consumer needs. Why is it? Because the thread version and the hardcover version of the moral although the packaging is different, but the same content, the Japanese version and the English version of the different, these two versions of the content may be different from the original, cultural differences, the content of the translation, although from the moral sutra, but according to different countries of the culture, thinking logic and so may change some ideas
Decorative mode is generally used in the following situations: the need to extend the functionality of a class or to give you a class to add additional responsibilities, the need to dynamically add functionality to an object, these functions can be re-dynamic revocation, need to add some basic functions of the permutation and produce a very large number of functions, So that the inheritance relationship becomes unrealistic.
The general use of adapter mode includes: The system needs to use the existing classes, but this class has not met the needs of the system;
You want to create a reusable class that works with some classes that are not much related to each other, including some classes that might be introduced in the future. The adapter mode is used very frequently when the system is upgraded, and some functional methods of the old system are referenced in the new system.
The I/O files in the decorating mode Java are reflected in the operation.
The classes in the Java IO Library that process streams have fileinputstream,fileoutputstream,datainputstream,dataoutputstream classes, and so on. Within the inputstream,outputstream,reader,writer structure, there are some stream processors that can decorate other stream processors to form new, improved stream processors. This reflects the role of decorative mode . There is also an adaptation reference to the functionality of other stream processors within some stream processors, which embodies the benefits of the adapter pattern .
The emergence of the concept of pattern, perfect to the rational application of the predecessors in the actual application of the continuous summary of the crystallization. For the different needs of the rational use of the model can play a multiplier effect, but the model is not universal, and the model is not inflexible, with the development of technology, engineers, the wisdom of summary, there may be a new pattern and the old mode of extinction, the model is for the actual needs of life, There is no need to rise to the height of philosophy.
Decorator mode, adapter mode, proxy mode difference