using System; using System.Collections.Generic; using System.Text; ///Prototype(原型)模式用于动态抽取当前对象运行时的状态,从自身构造出一个新的对象,即自身的拷贝(往往是深拷贝)。 ///add by jzh 2007-04-15 namespace DesignPattern { abstract class AbstractPrototype { abstract public AbstractPrototype CloneYourself(); } class MyPrototype : AbstractPrototype { override public AbstractPrototype CloneYourself() { return ((AbstractPrototype)MemberwiseClone()); } } class Demo { private AbstractPrototype internalPrototype; public void SetPrototype(AbstractPrototype thePrototype) { internalPrototype = thePrototype; } public void SomeImportantOperation() { AbstractPrototype x; x = internalPrototype.CloneYourself(); Console.WriteLine("完成复制"); } } public class Client { public static void Main(string[] args) { Demo demo = new Demo(); MyPrototype clientPrototype = new MyPrototype(); demo.SetPrototype(clientPrototype); demo.SomeImportantOperation(); Console.ReadLine(); } } }