using System; using System.Collections.Generic; using System.Text; using System.Threading; ///Prototype(原型)模式 用于解决在直接访问对象不方便或不符合要求时,为这个对象提供一种代理,以控制对该对象的访问。 ///add by jzh 2007-04-15 namespace DesignPattern { /// <summary> /// Summary description for Client. /// </summary> abstract class CommonSubject { abstract public void Request(); } class ActualSubject : CommonSubject { public ActualSubject() { Console.WriteLine("开始构造"); Thread.Sleep(1000); Console.WriteLine("完成构造"); } override public void Request() { Console.WriteLine("执行请求"); } } class Proxy : CommonSubject { ActualSubject actualSubject; override public void Request() { if (actualSubject == null) actualSubject = new ActualSubject(); actualSubject.Request(); } } public class Client { public static void Main(string[] args) { Proxy proxy = new Proxy(); proxy.Request(); Console.ReadLine(); } } }