步骤:
1. 创建抽象原型类,内有抽象方法Clone()
2. 创建具体原型类。
//抽象原型类
public abstract class AbstractPrototype
{
public abstract AbstractPrototype Clone();
}
//真实原型类
public class RealPrototype: AbstractPrototype
{
public int ID { get; set; }
public override AbstractPrototype Clone()
{
RealPrototype realPrototype = new RealPrototype();
realPrototype.ID = ID;
return realPrototype;
}
}
3.客户端实现
class Program
{
static void Main(string[] args)
{
RealPrototype realPrototype = new RealPrototype()
{
ID = 1
};
RealPrototype realPrototypeClone = (RealPrototype)realPrototype.Clone();
realPrototypeClone.ID = 2;
Console.ReadKey();
}
}