预览加载中,请您耐心等待几秒...
1/6
2/6
3/6
4/6
5/6
6/6

在线预览结束,喜欢就下载吧,查找使用更方便

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

介绍用原型实例指定创建对象的种类,并且通过拷贝这个原型来创建新的对象。示例有一个Message实体类,现在要克隆它。MessageModel usingSystem;usingSystem.Collections.Generic;usingSystem.Text;namespacePattern.Prototype{/**////<summary>///Message实体类///</summary>publicclassMessageModel{/**////<summary>///构造函数///</summary>///<paramname="msg">Message内容</param>///<paramname="pt">Message发布时间</param>publicMessageModel(stringmsg,DateTimept){this._message=msg;this._publishTime=pt;}privatestring_message;/**////<summary>///Message内容///</summary>publicstringMessage{get{return_message;}set{_message=value;}}HYPERLINK"http://qianming.wan128.cn"http://qianming.wan128.cnprivateDateTime_publishTime;/**////<summary>///Message发布时间///</summary>publicDateTimePublishTime{get{return_publishTime;}set{_publishTime=value;}}}} ShallowCopy usingSystem;usingSystem.Collections.Generic;usingSystem.Text;namespacePattern.Prototype{/**////<summary>///浅拷贝///</summary>publicclassShallowCopy:ICloneable{/**////<summary>///构造函数///</summary>publicShallowCopy(){}/**////<summary>///实现ICloneable的Clone()方法///</summary>///<returns></returns>publicObjectClone(){returnthis.MemberwiseClone();}HYPERLINK"http://yin.qqlove789.com"http://yin.qqlove789.comprivateMessageModel_mm;/**////<summary>///Message实体对象///</summary>publicMessageModelMessageModel{get{return_mm;}set{_mm=value;}}}} DeepCopy usingSystem;usingSystem.Collections.Generic;usingSystem.Text;namespacePattern.Prototype{/**////<summary>///深拷贝///</summary>publicclassDeepCopy:ICloneable{/**////<summary>///构造函数///</summary>publicDeepCopy(){}/**////<summary>///构造函数///</summary>///<paramname="mm">Message实体对象</param>publicDeepCopy(MessageModelmm){_mm=mm;}/**////<summary>///实现ICloneable的Clone()方法///</summary>///<returns></returns>publicObjectClone(){returnnewDeepCopy(newMessageModel(_mm.Message,_mm.PublishTime));}privateMessageModel_mm;/**////<summary>///Message实体对象///</summary>publicMessageModelMessageModel{get{return_mm;}set{_mm=value;}}}} client usingSystem;usingSystem.Data;usingSystem.Configuration;usingSystem.Colle