Cooking-adapter and appearance Mode

Source: Internet
Author: User
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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.