Analysis of adapter and bridge mode

Source: Internet
Author: User

      There are some more confusing patterns in design mode, such as adapter mode and bridging mode, all of which allow two classes to work in one piece
  However, although they are very similar, are indirect reference objects, there will be different, let's look at the following analysis
One, each said its long
    The adapter mode says, "I'm the interface that transforms a class's interface into another class so they can work together. ”
    Bridging mode says, "What is there that I can separate the abstraction from the realization, and let them do it separately?"
    Adapter mode refused, then said: "Yao in the NBA playing basketball, the coach to arrange tactics, but he can not understand, need to translate, then turn
  The role of the adapter, I can put Yao and coach fit to a piece, so that Yao can understand the tactics, you can? ”
    Bridging mode A contemptuous smile: "Although I can not start the adaptation role, but I can abstract mobile phone function and mobile phone brand, so that the same work
  Can be used in different brands, the same brand can use different functions, you can resemble if there is no bridging mode, then a function can only be
It's a   special phone, isn't it sad? "
Second, Comparison
  From the top of the adapter and bridge mode is to let two classes work in one piece, then what is the difference between them?
    Adapter mode: Change the interface to allow two classes to be compatible
    Bridging mode: Separate abstraction and implementation, interface different, purpose is to separate
    So to speak: if there are now two modules, you want them to work in a piece, then use adapter mode;
    is to separate the implementation, then the bridge mode, bridge mode implementation, both sides of the things can be free change, but the interface is stable
  Two modes of application with different design stages
    Bridge mode is applied in the early stage of the design, and the force is more flexible in the system. Adapter mode applications Some classes do not work together after the design is complete.
    Then use the adapter mode
  In general, adapter mode and bridge mode will appear in pairs
Iii. Summary
  Learn to learn from the old knowledge, and learn to compare learning, then learn more efficient
  Design mode of learning is not finished, after the accumulation of 1.1 points

Analysis of adapter and bridge mode

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.