[索引页]
[源码下载]


乐在其中设计模式(C#) - 适配器模式(Adapter Pattern)


作者:webabcd


介绍
将一个类的接口转换成客户希望的另外一个接口。Adapter模式使得原本由于接口不兼容而不能一起工作的那些类可以一起工作。


示例
有一个Message实体类,某个类对它的操作有Insert()和Get()方法。现在需要把这个类转到另一个接口,分别对应Add()和Select()方法。
乐在其中设计模式(C#) - 适配器模式(Adapter Pattern)


MessageModel
乐在其中设计模式(C#) - 适配器模式(Adapter Pattern)using System;
乐在其中设计模式(C#) - 适配器模式(Adapter Pattern)
using System.Collections.Generic;
乐在其中设计模式(C#) - 适配器模式(Adapter Pattern)
using System.Text;
乐在其中设计模式(C#) - 适配器模式(Adapter Pattern)
乐在其中设计模式(C#) - 适配器模式(Adapter Pattern)
namespace Pattern.Adapter

SqlMessage
乐在其中设计模式(C#) - 适配器模式(Adapter Pattern)using System;
乐在其中设计模式(C#) - 适配器模式(Adapter Pattern)
using System.Collections.Generic;
乐在其中设计模式(C#) - 适配器模式(Adapter Pattern)
using System.Text;
乐在其中设计模式(C#) - 适配器模式(Adapter Pattern)
乐在其中设计模式(C#) - 适配器模式(Adapter Pattern)
namespace Pattern.Adapter

IMessage
乐在其中设计模式(C#) - 适配器模式(Adapter Pattern)using System;
乐在其中设计模式(C#) - 适配器模式(Adapter Pattern)
using System.Collections.Generic;
乐在其中设计模式(C#) - 适配器模式(Adapter Pattern)
using System.Text;
乐在其中设计模式(C#) - 适配器模式(Adapter Pattern)
乐在其中设计模式(C#) - 适配器模式(Adapter Pattern)
namespace Pattern.Adapter

Message
乐在其中设计模式(C#) - 适配器模式(Adapter Pattern)using System;
乐在其中设计模式(C#) - 适配器模式(Adapter Pattern)
using System.Collections.Generic;
乐在其中设计模式(C#) - 适配器模式(Adapter Pattern)
using System.Text;
乐在其中设计模式(C#) - 适配器模式(Adapter Pattern)
乐在其中设计模式(C#) - 适配器模式(Adapter Pattern)
namespace Pattern.Adapter

Message2
乐在其中设计模式(C#) - 适配器模式(Adapter Pattern)using System;
乐在其中设计模式(C#) - 适配器模式(Adapter Pattern)
using System.Collections.Generic;
乐在其中设计模式(C#) - 适配器模式(Adapter Pattern)
using System.Text;
乐在其中设计模式(C#) - 适配器模式(Adapter Pattern)
乐在其中设计模式(C#) - 适配器模式(Adapter Pattern)
namespace Pattern.Adapter


client
乐在其中设计模式(C#) - 适配器模式(Adapter Pattern)using System;
乐在其中设计模式(C#) - 适配器模式(Adapter Pattern)
using System.Data;
乐在其中设计模式(C#) - 适配器模式(Adapter Pattern)
using System.Configuration;
乐在其中设计模式(C#) - 适配器模式(Adapter Pattern)
using System.Collections;
乐在其中设计模式(C#) - 适配器模式(Adapter Pattern)
using System.Web;
乐在其中设计模式(C#) - 适配器模式(Adapter Pattern)
using System.Web.Security;
乐在其中设计模式(C#) - 适配器模式(Adapter Pattern)
using System.Web.UI;
乐在其中设计模式(C#) - 适配器模式(Adapter Pattern)
using System.Web.UI.WebControls;
乐在其中设计模式(C#) - 适配器模式(Adapter Pattern)
using System.Web.UI.WebControls.WebParts;
乐在其中设计模式(C#) - 适配器模式(Adapter Pattern)
using System.Web.UI.HtmlControls;
乐在其中设计模式(C#) - 适配器模式(Adapter Pattern)
乐在其中设计模式(C#) - 适配器模式(Adapter Pattern)
using Pattern.Adapter;
乐在其中设计模式(C#) - 适配器模式(Adapter Pattern)
乐在其中设计模式(C#) - 适配器模式(Adapter Pattern)
public partial class Adapter : System.Web.UI.Page

运行结果
类适配器方式
True
SQL方式获取Message 2007-4-8 20:59:29

对象适配器方式
True
SQL方式获取Message 2007-4-8 20:59:29


参考
http://www.dofactory.com/Patterns/PatternAdapter.aspx


OK
[源码下载]

相关文章:

  • 2021-11-04
  • 2022-12-23
  • 2021-06-06
  • 2021-11-09
  • 2021-11-30
  • 2021-08-26
猜你喜欢
  • 2021-11-06
  • 2021-05-25
  • 2021-06-01
  • 2021-07-27
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案