接口模式 - 1.1 适配器模式 --代码实现(C#)
来源:互联网 发布:淘宝图片保护在哪里看 编辑:程序博客网 时间:2024/06/04 08:45
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
IDoSome_target idosome = new DoSome_Adapter();
idosome.request();
Console.ReadKey();
IDoSome_target2 idosome2 = new DoSome_Adapter2();
idosome2.request();
Console.ReadKey();
IDoSome_target3 idosome3 = new DoSome_Adapter3();
idosome3.request();
Console.ReadKey();
}
}
# region 类适配器模式
/// <summary>
/// 当客户(Client)已存在固定接口(IDoSome_target)时,而新开发的类的(DoSome)方法名或者方法不符合客户调用的时候,
/// 需要创建一个中间类(DoSome_Adapter)来调用已经存在的类,可以使用类适配器模式
/// </summary>
interface IDoSome_target
{
void request();
}
public class DoSome
{
public void specialRequest()
{
Console.WriteLine("reponse to special request!");
}
}
public class DoSome_Adapter:DoSome,IDoSome_target
{
public void request()
{
this.specialRequest();
}
}
#endregion
# region 对象适配器模式
/// <summary>
/// 当客户(Client) 未定义接口,而是一个类(Target),新开发的类的(Adaptee)方法名或者方法不符合客户调用的时候,
/// 需要创建一个中间类(Adapter)来调用已经存在的类,可以使用对象适配器模式
/// </summary>
public class IDoSome_target2
{
public virtual void request() { Console.WriteLine("2--"); }
}
public class DoSome2
{
public void specialRequest()
{
Console.WriteLine("2---reponse to special request!");
}
}
public class DoSome_Adapter2 :IDoSome_target2
{
private DoSome2 _DoSome2= new DoSome2();
public override void request()
{
_DoSome2.specialRequest();
}
}
#endregion
# region 对象适配器模式2
/// <summary>
/// 当客户(Client) 未定义接口,而是一个类(Target),新开发的类的(Adaptee)方法名或者方法不符合客户调用的时候,
/// 需要创建一个中间类(Adapter)来调用已经存在的类,可以使用对象适配器模式
/// </summary>
public abstract class IDoSome_target3
{
public abstract void request();
}
public class DoSome3
{
public void specialRequest()
{
Console.WriteLine("3---reponse to special request!");
}
}
public class DoSome_Adapter3 : IDoSome_target3
{
private DoSome3 _DoSome3 = new DoSome3();
public override void request()
{
_DoSome3.specialRequest();
}
}
#endregion
}
- 接口模式 - 1.1 适配器模式 --代码实现(C#)
- 适配器模式-C++代码实现
- 适配器模式C语言实现
- 接口转换--适配器模式
- 接口适配器模式
- 适配器模式(接口隔离)
- 适配器模式(接口)
- 转载-----C# 设计模式 - 1 接口模式 - 1.1 适配器模式
- 适配器模式及C++代码实现
- java的适配器模式简单代码实现
- C#适配器模式代码
- 适配器模式代码示例
- 【C++】Chapter13:适配器模式
- Objective C--适配器模式
- Objective C 适配器模式
- 适配器模式(C++)
- 适配器模式(C++)
- 适配器模式之单接口适配器
- 【转】单例模式完全剖析
- POJ 1426 见证模余的力量!
- JDK1.5新特性(转)
- oracle 10g rac for linux (ASM) 修改modify public IP and vip
- emacs初学,大家有意见就提哈
- 接口模式 - 1.1 适配器模式 --代码实现(C#)
- 程序员的十层楼
- hibernate的lazy使用
- ISAPI过滤器介绍与使用
- ZOJ 1276 纪录路径的DP,生成括号的方法很有效
- linux内核源代码学习(1)内存映射模式
- 程序人生的开始
- 为网站技术“牛”人充电的“牛”文!
- 创意图片