using System; using System.Collections.Generic; using System.Text; namespace PrototypeTest { class Program { static void Main(string[] args) { ConcretePrototype obj = new ConcretePrototype(); obj.Name = "aaa"; ConcretePrototype obj1 = (ConcretePrototype)obj.Clone(); Console.WriteLine(obj1.Name); Console.Read(); } } //Clone接口声明 public interface ICloneable { Object Clone(); } //原型类 public abstract class Prototype : ICloneable { public abstract Object Clone(); } //具体实现类 public class ConcretePrototype : Prototype { public string Name; public override Object Clone() { ConcretePrototype obj = new ConcretePrototype(); obj.Name = Name; return obj; } } }
运行测试