C # Design Pattern adapter Design pattern (Adapter)

Source: Internet
Author: User
Tags wrapper

Structural patterns (structural pattern) describe how a class or object can be combined to form a larger structure. The structure pattern describes two different things: a class and an instance of a class. According to this point, the structure pattern can be divided into the structure pattern of the class and the structure pattern of the object.

Subsequent content will include the following architectural patterns:

Adapter mode (Adapter): Match Interfaces of different classes

Synthetic mode (composite): A tree structure of the simple and composite objects

Decoration mode (decorator): Add responsibilities to objects dynamically

Agent mode (proxy): An object representing another object

Enjoy meta mode (Flyweight): A fine-grained instance used for efficient sharing

Façade mode (façade): A single class that represents an entire subsystem

Bridge mode (Bridges): Separates an object interface from its implementation

First, adapter (Adapter) mode

The adapter pattern transforms the interface of a class into another interface that the client expects, so that two classes that do not match the original interface can work together.

Origin of name

This is much like a transformer (Adapter), which transforms one voltage into another. Electricity in the United States is 110V and the voltage in China is 220V. If you want to use American electrical appliances in China, you must have a transformer that converts a 220V voltage to a 110V voltage. This transformer is a adapter.

The adapter model is also similar to the packing process of the goods: the real appearance of the packaged goods is concealed and changed by the packaging, so some people call this pattern the packaging (wrapper) mode. In fact, we often write many of these wrapper classes, wrapping up some of the existing classes so that they can meet the needs of the interface.

Two forms of Adapter pattern

Adapter mode has both the adapter mode of the class and the adapter pattern of the object. We will discuss both of these adapter modes separately.

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.