Adapter patterns for. NET design pattern instances (Adapter pattern)

Source: Internet
Author: User
Tags abstract

Introduction of Adapter Mode (Brief Introduction)

Adapter mode to replace a class with another interface expected by the customer. The adapter mode makes it possible for those classes that are not working because of incompatible interfaces to work together.

Ii. issues addressed (What to Solve)

1, the use of Third-party components, and the interface of this component is incompatible with the current system interface (such as methods and system methods inconsistent, etc.), you can use adapter mode to resolve interface incompatibility problems.

2, using the earlier project some useful classes, you can use the adapter mode to solve the existing interface and the original object interface incompatibility problem.

Adapter Mode Analysis 1, adapter mode structure

2, source code

1, customer-expected interface or abstract class target

public abstract class Target
{
     public abstract void Request();
}

2, to fit the class adaptee, that is, the expected call interface does not match the class

public class Adaptee
{
     public void SepecificRequest()
     {
         Console.WriteLine("执行要适配类的特殊请求方法");
     }
}

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.