I. Overview
The adapter mode of the class converts the API of the adapted class into the target class.
Second, the structure
1, class adapter mode
Target: I look forward to the interface
Adaptee: Categories that need to be adapted
Adapter: Transform the source interface into the core class of the target interface
2, the adapter mode of the object
I, the same adapter can adapt the source and its subclasses to the target interface
II, compared with the adapter of the class, the method of coverage is not easy, unless a subclass of a source class, then the subclass adaptation
III, you can easily add a method
Third, motive
1. The system needs to use an existing class, and the interface of the interface does not meet the needs of the system.
2. Working with a class that can be established to make some classes that do not have too much relationship between each other.
3. Need to change the interface of multiple existing subclasses