Design Concept and Mode 2 adapter mode and thought adapter Mode

Source: Internet
Author: User

Design Concept and Mode 2 adapter mode and thought adapter Mode
1. What is the adapter mode?

The adapter mode is a transitional mode used to communicate two incompatible things and exchange information.

2. Purpose of the adapter Mode

Allows an object to process multiple objects of different types in a relatively simple way, that is, an object is compatible with multiple objects of different types. For example, the plug-in of the computer's external hardware is uniquely identified. Memory Cards of different sizes are first inserted into the card reader, and then inserted into the unique plug-in by the card reader. The card reader acts as an adapter. Different memory cards have different card readers. Because different card readers face the same plug-in, different card readers share the same features, in the program, the adapter implements a common interface, reflecting the interface pluggable feature.

 

3. Interface pluggable features:

The interface implements a certain specification, and the Implementation class of the interface implements the specification more specifically. Any implementation class is effective for this specification, so when you need to implement the specification, you can use any implementation class.


4. the adapter is a modifier that encapsulates the processing object and indirectly executes the processing object method by calling the method of the adapter.

5. Determine the adapter

An adapter corresponds to a type of processor. You can define a method within the adapter to determine whether the receiving object is a type of object. You can retrieve the corresponding adapter by traversing the adapter.

6. Structure of the adapter Mode

(1) Central Scheduler: the object that the processor communicates with through the adapter.
(2) Adapter interface: To ensure that multiple adapters can communicate with the central scheduler, a specification for interaction with the central scheduler is developed.
(3) Adapter implementation class: implements the adapter interface and adds an instanceof method to determine whether an object is a specified receiving object ).
(4) processor interface: a specification is defined for a type of processor, which corresponds to an adapter implementation class.
Worker processor implementation class: implements the processor interface and is the object actually processed by the central scheduler.

In summary, the adapter mode consists of one central scheduler, two interfaces, and two implementation classes.

 

7. Under what circumstances do I use the adapter mode? The adapter mode is used to exchange information between a relatively fixed object and a variable object. When an object needs to process multiple objects of different classes, the adapter mode is used.

 

Related Article

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.