Interview questions-java Design Pattern Example 1, adapter mode
Involves three roles: Target destination interface, Adaptee source role, adapter adapter,adapter The source interface to the target interface, inherits the source interface, and implements the target interface .
Many examples of Java I/O operations are:
InputStreamReader the inputstream to reader; you need to inherit inputstream to implement reader.
OutputStreamWriter the outputstream adaptation to Writer;
StringReader applies the String class to Reader;
2. Adorner mode
Involves three roles: Component abstract component roles, concretecomponent implements all functions of the abstract component, decorator adorner role, it holds a reference to a Component object instance, defines an interface that is consistent with the abstract component, Concretedecorator specific decorator implementations.
Adorner mode in Java I/O: FilterInputStream class;
Note: Both adapter and adorner modes are wrapper modes, and they appear to be a reference for wrapping a class or object, but the purpose of using them is different; the meaning of adapter mode is to change the interface to achieve the purpose of re-use, the adorner mode is to maintain the original interface, enhance the function of the original object.
An example of-java design pattern for interview questions