作者:vuefine
文献:大话设计模式 | 程杰
平台:.NET 2.0+
问题分析
有的场合下,我们需要浅复制便能解决问题,因为我们复制出来的实例,仍然引用原来的初始对象。但是,有时候浅复制得到的实例上的属性值还要做出调整,并且保证不能影响原始对象,这样只能深度复制才能做到。
应用举例
首先看一下浅复制为什么不能满足我们的要求。我们要复制简历,并且复制出的版本只有一处不同于模板简历的求职意向中的公司名称。
简历模型1.0版本:
public class ResumeInfoShell:ICloneable
{
public ResumeInfoShell(string name, string telephone, EducationInfo educationInfo,WantedJobShell job)
{
this._name = name;
this._telephone = telephone;
this._educationInfo = educationInfo;
this._wantedJob = job;
}
private string _name;
public string name
{
get { return this._name; }
}
private string _telephone;
public string telephone
{
get { return _telephone; }
}
private EducationInfo _e