public partial class 原型模式 : Form
{
public 原型模式()
{
InitializeComponent();
}
private void 原型模式_Load(object sender, EventArgs e)
{
kehuduan.sss();
}
}
abstract class Prototype
{
private string id;
public Prototype(string id)
{
this.id = id;
}
public string Id
{
get { return id; }
}
public abstract Prototype Clone();
}
class ConcretePrototype1 : Prototype
{
public ConcretePrototype1(string id) : base(id)
{
}
public override Prototype Clone()
{
return (Prototype)this.MemberwiseClone();
}
}
class kehuduan
{
public static void sss()
{
ConcretePrototype1 p1 = new ConcretePrototype1("i");
ConcretePrototype1 c1 = (ConcretePrototype1)p1.Clone();
var x = c1.Id;
}
}
class Resume : ICloneable
{
private string name;
private string sex;
private string age;
private string timeArea;
private string company;
public Resume(string name)
{
this.name = name;
}
public void SetPersonalInfo(string age,string sex)
{
this.age = age;
this.sex = sex;
}
public void SetWorkExperience(string timeArea,string company)
{
this.timeArea = timeArea;
this.company = company;
}
public void Display()
{
Console.WriteLine("{0}{1}{2}",name,sex,age);
Console.WriteLine("{0}{1}", timeArea, company);
}
public object Clone()
{
return (object)this.MemberwiseClone();
}
}
class kehuduan1
{
public static void sss()
{
Resume a = new Resume("大料");
a.SetPersonalInfo("1","1");
a.SetWorkExperience("1","1");
Resume b = (Resume)a.Clone();
}
}
class WorkExperience
{
private string workDate;
public string WorkDate
{
get { return workDate; }
set { workDate = value; }
}
private string company;
public string Company
{
get { return company; }
set { company = value; }
}
}
class Resume1 : ICloneable
{
private string name;
private string sex;
private string age;
private WorkExperience work;
public Resume1(string name)
{
this.name = name;
work = new WorkExperience();
}
public object Clone()
{
return (object)this.MemberwiseClone();
}
public void SetPersonalInfo(string age, string sex)
{
this.age = age;
this.sex = sex;
}
public void SetWorkExperience(string workDate, string company)
{
work.WorkDate = workDate;
work.Company = company;
}
}
class kehuduan2
{
public static void sss()
{
Resume a = new Resume("大料");
a.SetPersonalInfo("1", "1");
a.SetWorkExperience("1", "1");
Resume b = (Resume)a.Clone();
}
}