Design Pattern _ adapt

Source: Internet
Author: User

An image example:

(Adapter) I met Sarah, a beautiful girl from Hong Kong at a friend's party. But I can't speak Cantonese, and she can't speak Mandarin, so I have to turn to my friend Kent, as an adapter between me and Sarah, Sarah and I can talk to each other (I don't know if he will play with me ).

Adapter (transformer) mode:

The interface of a class is transformed into another interface expected by the client, so that the two classes that cannot work together due to interface mismatch can work together. The adaptation class can return a suitable instance to the client based on the parameters.

UML:
1) inherit the original Interface Class

2) combine original interface classes

Resolution:
The adapt mode is actually to bridge the classes that have completed the same function but are incompatible with the interfaces so that they can work together. This mode makes it possible to reuse the old interfaces.

Implementation:
The adapt mode has two implementation methods: one is to inherit the original interface class method, the other is to combine the original interface class method, the second method is used here.

 

Design Pattern _ adapt

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.