Adapter mode (Adapter pattern)

Source: Internet
Author: User

Https://en.wikipedia.org/wiki/Adapter_pattern

It allows the interface of an existing class to be used as another interface.

It is often used to make existing classes work with others without modifying their source code.

Scenario: let an existing class work correctly based on other classes, and do not need to modify their source code.

Example: Notebook power Adapter (Adapter), so that the notebook (client) work properly, using AC (adaptee), do not modify the notebook or modify the AC.

UML Class Diagrams:

That is

The client class has a target member variable (eventually upward transformation, referring to an instance of the implementation class adapter)

The target interface has the request () method

The adapter class has a Adaptee member variable

The adapter class is the implementation class of the target interface, implementing the request () method, calling the Specificrequest () method of the Adaptee class in the method body

Summary: No change to client, no change to adaptee.

Interface Implementation Class

Adapter mode (Adapter pattern)

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.