today, I saw the adapter mode and appearance mode, which are summarized as follows: 1. adapter and appearance: A conversion interface, One is a simplified interface, but there is no big difference between the two
2. when two modules are coupled, it is best to have an intermediate module. Assuming that the interface remains unchanged after the caller defines the interface, the called interface may change. If an adapter acts as the intermediate module, the new interface can be adapted to the old interface, so that after the caller changes, the caller does not need to modify the Code , you only need to modify the code of the adapter and use this to decouple it. At the initial stage of coupling between the two modules, the adapter should be designed to further encapsulate the caller to adapt to the caller 3. class adapter and Object Adapter: one step Cheng, a combination. Class adaptation means that the adapter inherits the adaptation and the adaptation at the same time. The interface of the adapter can be used to reduce the amount of Code. For example, you only need to adapt to one interface, you don't need to worry about other interfaces. If you use an Object Adapter, all the interfaces of the adapter must be implemented again. I prefer object adapters. This is more flexible. If an interface requires operations from multiple adaptors, you need a pot or a stove for cooking, now the caller needs a cook interface. You need to combine multiple adaptors to implement this interface. If inheritance is used, it will inherit a lot of irrelevant things from the adapter. If you need to use some methods of the Child classes of the adapter, it will be more troublesome. It is king to use multiple combinations and less inheritance. 4. Summary of the OO principle: the fewer other modules coupled with one module, the better. The less the underlying implementation of the other module, the better. When two modules are coupled, adding an intermediate module will increase the flexibility of coupling and clean the interface. 5. I call these two cooking modes .......
The two figures below are copied from the Internet.
Object Adapter:
Class adapter: