设计模式7-适配器模式

适配器模式:将一个接口转换成业务需要的另一个接口,使原本因为接口不兼容不能一起工作的类可以一起工作。

多用于软件的修护,修改阶段。重用已存在的资源类。

接口不相同时,如果双方都不容易修改使用,否则重构统一接口就好,大可不必适配,模式是为解决问题,不可生搬硬套。

 1 namespace DesignModel.适配器模式
 2 {
 3     interface Bll
 4     {
 5         void Reqeust();
 6     }
 7     class OldBll
 8     {
 9         public void OldRequest()
10         {
11             Console.WriteLine("");
12         }
13     }
14 
15     class Adapter : Bll
16     {
17         OldBll ob = new OldBll();
18         public void Reqeust()
19         {
20             ob.OldRequest();
21         }
22     }
23 
24 }
25 
26 static void 适配器模式()
27       {
28           Bll bll = new Adapter();
29           bll.Reqeust();
30       }
View Code
原文地址:https://www.cnblogs.com/liurui/p/5537139.html