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("执行要适配类的特殊请求方法");
}
}