
using System;
using System.Collections.Generic;
using System.Text;
///Adapter(适配器)模式又称Wrapper模式,
///通过适配器解决两个已有接口之间匹配问题。
///add by jzh 2007-04-13
namespace DesignPattern
{
/// <summary>
/// 目标(Target)角色:目标接口。
/// </summary>
class Target
{
virtual public void GetAction(string action)
{
}
}
/// <summary>
/// 源(Source)角色:源接口。
/// </summary>
class Source
{
public void GetAction(string action)
{
Console.WriteLine("Action = {0}", action);
}
}
/// <summary>
/// 适配器(Adapter)角色:通过在内部包装(Wrap)一个Adaptee对象,把源接口转换成目标接口。
/// </summary>
class Adapter : Target
{
private Source source = new Source();
override public void GetAction(string action)
{
string transfer;
transfer = "cts/" + action.ToString();
source.GetAction(transfer);
}
}
public class Client
{
public static void Main(string[] args)
{
Target target = new Adapter();
target.GetAction("getUser");
Console.ReadLine();
}
}
}