ITPub博客

首页 > 应用开发 > IT综合 > 设计模式之C#实现(四)---- ProtoType之二(转)

设计模式之C#实现(四)---- ProtoType之二(转)

原创 IT综合 作者:hphubei 时间:2007-07-08 15:07:45 0 删除 编辑
下面是一个浅拷贝的例子:

using System;



namespace Prototype_Shallow{

//因为我们在FCL里面已经有这样的接口所以我们就不定义新的Prototype了

public class ConcretePrototype1 : ICloneable{

private int m_ID;

public int ID{

get{

return this.m_ID;

}

}

public ConcretePrototype1(int id){

this.m_ID = id;

}



public object Clone(){

return this.MemberwiseClone();

}

}



public class ConcretePrototype2 : ICloneable{

private int m_ID;

public int ID

{

get

{

return this.m_ID;

}

}

public ConcretePrototype2(int id){

this.m_ID = id;

}

public object Clone(){

return this.MemberwiseClone();

}

}



}[@more@]

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/79548/viewspace-925309/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
  • 博文量
    181
  • 访问量
    274758