Design pattern Learning--Adapter mode

Source: Internet
Author: User

Introduced:

There are a lot of adapters in reality. Like a transformer, I would like to read this article you, is probably a student (at least once). Because right now in the dormitory to write this blog. I am in the dormitory will be rationing, high voltage will trip, can not use such equipment as induction cooker, you know, the university, the occasional dormitory members in the dormitory, can not use some cooking equipment, too inhuman there is wood (the system of spitting under the school), but there are some things called "Transformers" on the Internet, can help you solve this problem. Transformers can convert voltages. For example, the 220v into 110v, because of it, the dormitory can eat pot Na!

Here the work of the transformer is like the work of the adapter mode, so the adapter mode is often called the transformer mode. Then use the example on head, more image.

Object-oriented adapters:

Suppose you already have a software system that you want to use with a new vendor class library, but the interface that this new vendor involves is different from the old vendor's interface.

Then, we do not want to change the existing code, and can not change the manufacturer's code, so how to solve this problem. You can write another class that transforms the new vendor interface into the interface you expect.

This adapter is like a middleman that connects existing systems with vendor classes.

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.