代理模式

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DaiLiMoShi
{
class XiMengQing
{
static void Main(string[] args)
{
WangPo wp = new WangPo();
wp.makeEyesWithMan();
wp.happyWithMan();
Console.WriteLine("--------------------------------------");
WangPo wpjs = new WangPo(new JiaShi());
wpjs.makeEyesWithMan();
wpjs.happyWithMan();
Console.ReadKey();
}
}
//定义一种类型的女人,王婆和潘金莲都属于这个类型的女人
public interface KindWomen
{
//这种类型的女人能做什么事情呢?
void makeEyesWithMan();
void happyWithMan();
}
public class PanJinLian : KindWomen
{
public void makeEyesWithMan()
{
Console.WriteLine("潘金莲抛媚眼.......");
}
public void happyWithMan()
{
Console.WriteLine("潘金莲和XXXX.......");
}
}
public class WangPo:KindWomen
{
private KindWomen kindwomen;
//默认作为潘金莲的代理
public WangPo()
{
this.kindwomen = new PanJinLian();

}
//她可以是KindWomen的任何一个女人的代理,只要你是这一类型
public WangPo(KindWomen kw)
{
this.kindwomen = kw;

}
public void makeEyesWithMan()
{
this.kindwomen.makeEyesWithMan();
}
public void happyWithMan()
{
this.kindwomen.happyWithMan();
}

}
public class JiaShi : KindWomen
{
public void makeEyesWithMan()
{
Console.WriteLine("贾氏抛媚眼.......");
}
public void happyWithMan()
{
Console.WriteLine("贾氏和XXXX.......");
}
}
/*
* 水浒里是这样写的:西门庆被潘金莲用竹竿敲了一下难道,痴迷了,
* 被王婆看到了, 就开始撮合两人好事,王婆作为潘金莲的代理人
* 收了不少好处费,那我们假设一下:
* 如果没有王婆在中间牵线,这两个不要脸的能成吗?难说的很!
*/

}

posted @ 2014-03-03 17:21  life steven  阅读(173)  评论(0编辑  收藏  举报