标签:
1.代理模式
为其他对象提供代理以控制对这个对象的访问。
2.实例
namespace 代理模式 { class Program { static void Main(string[] args) { GirlMM mm = new GirlMM(); mm.Name = "夏花"; Proxy proxy = new Proxy(mm); proxy.GiveDolls(); proxy.GiveFlowers(); proxy.GiveChocolate(); Console.ReadLine(); } } /// <summary> /// 被代理对象执行的操作接口 /// </summary> interface IGiveGift { void GiveDolls(); void GiveFlowers(); void GiveChocolate(); } /// <summary> /// 被代理者希望代理执行操作的类 /// </summary> class GirlMM { private string name; public string Name { get { return name; } set {name = value;} } } /// <summary> /// 被代理者 /// </summary> class Pursuit: IGiveGift { GirlMM mm; public Pursuit(GirlMM mm) { this.mm = mm; } public void GiveDolls() { Console.WriteLine(mm.Name+"送你洋娃娃"); } public void GiveFlowers() { Console.WriteLine(mm.Name + "送你鲜花"); } public void GiveChocolate() { Console.WriteLine(mm.Name + "送你巧克力"); } } class Proxy:IGiveGift { Pursuit gg; public Proxy(GirlMM mm) { gg = new Pursuit(mm); } public void GiveDolls() { gg.GiveDolls(); } public void GiveFlowers() { gg.GiveFlowers(); } public void GiveChocolate() { gg.GiveChocolate(); } } }
标签:
原文地址:http://www.cnblogs.com/Firepad-magic/p/4704049.html