标签:
using System; namespace ConsoleApplication6 { class Program { static void Main(string[] args) { // 创建一个代理对象并发出请求 Person proxy = new Friend(); proxy.BuyProduct(); Console.Read(); } } // 抽象主题角色 public abstract class Person { public abstract void BuyProduct(); } //真实买家 public class RealBuyPerson : Person { public override void BuyProduct() { Console.WriteLine("真实买家买一个IPhone和一台苹果电脑"); } } // 代理角色 public class Friend : Person { RealBuyPerson realSubject; public override void BuyProduct() { if (realSubject == null) { realSubject = new RealBuyPerson(); } realSubject.BuyProduct(); Console.WriteLine("调用代理类叫朋友去买"); this.PreBuyProduct(); this.PostBuyProduct(); } public void PreBuyProduct() { Console.WriteLine("朋友去买一个IPhone和一台苹果电脑"); } public void PostBuyProduct() { Console.WriteLine("朋友去把IPhone和一台苹果电脑交给真实买家"); } } }
标签:
原文地址:http://www.cnblogs.com/lgxlsm/p/4641875.html