Design Mode Learning (7) Adapter Mode

Source: Internet
Author: User
In the adapter modeProgramThe design interface is converted into another interface. When we want unrelated classes to work together in a program, we can use the adapter mode. The concept of an adapter is quite simple: compile a class with the required interface, and then let it communicate with the class with different interfaces.

Class adapter: derives a new class from an inconsistent class, and then adds the required method so that the new derived class can match the required interface.

Object Adapter: contains the original class in the new class, and then creates a method in the new class to convert the call.

Understanding: In the adapter mode, you can include controls in the adapter class in actual applications and then call them directly.

Differences between class adapters and object adapters:

1When we want to match a class and all its subclasses, the class adapter will not be competent, because the base class derived from the subclass has been defined at the time of creating the subclass.

2The class adapter allows the adapter to change methods of some matched classes, and also allows other unmodified methods.

3The Object Adapter allows all child classes to be matched by passing subclass to the constructor.

4The Object Adapter requires the reader to put the method of matching the object to the surface.

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: 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.