标签:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
/*
为方便统一接口。通过适配器来转换调用
*/
namespace App_MYCS.HDL_SJMS.SPCMS
{
class my_SPCMS
{
public void dy()
{
Target target = new Adapter();
target.Request();
}
}
//
class Target
{
public virtual void Request()
{
Console.WriteLine("普通请求");
}
}
class Adaptee
{
public void SpecificRequest()
{
Console.WriteLine("特别请求");
}
}
class Adapter : Target
{
private Adaptee adaptee = new Adaptee();
public override void Request()
{
adaptee.SpecificRequest();
}
}
//--------------------------------------------
interface I1
{
string abc1();
}
class I1class:I1
{
public string abc1()
{
return "abc1";
}
}
//
class I1class2
{
public string bca1()
{
return "bca1";
}
}
//适配 I1class2 可以实现接口
class I1class1 : I1
{
I1class2 i1 = new I1class2();
public string abc1()
{
return i1.bca1();
}
}
class dyclass
{
I1 i = new I1class();
I1 j = new I1class1();
//适配后就可以统一方式进行调用
}
}
标签:
原文地址:http://www.cnblogs.com/longkai178/p/5815122.html