日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

《设计模式系列》---克隆模式

發(fā)布時間:2025/3/15 asp.net 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 《设计模式系列》---克隆模式 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

2019獨角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>

淺復(fù)制:被復(fù)制對象的所有變量都含有與原來的對象相同的值,而所有的對其他對象的引用都仍然指向原來的對象.

/***?@author?stefanie?zhao*?@date?2014-8-15?下午02:31:04*/ public?class?Resume?implements?Cloneable?{private?String?name;private?String?sex;private?String?age;private?WorkExperience?work;public?Resume(String?name)?{this.name?=?name;work?=?new?WorkExperience();}public?void?setPersonalInfo(String?sex,?String?age)?{this.sex?=?sex;this.age?=?age;}public?void?setWorkExperience(String?workDate,?String?company)?{work.setCompany(company);work.setWorkDate(workDate);}public?Object?clone()?{Object?re?=?null;try?{return?(Object)?super.clone();}?catch?(CloneNotSupportedException?e)?{//?TODO?Auto-generated?catch?blocke.printStackTrace();}return?re;}public?void?dispay()?{System.out.format("%s?%s?%s",?name,?sex,?age);System.out.format("工作經(jīng)歷:%s?%s",?work.getWorkDate(),?work.getCompany());} } /***?@author?stefanie?zhao*?@date?2014-8-15?下午02:29:23*/ public?class?WorkExperience?{private?String?workDate;private?String?company;/***?@return?the?workDate*/public?String?getWorkDate()?{return?workDate;}/***?@param?workDate*????????????the?workDate?to?set*/public?void?setWorkDate(String?workDate)?{this.workDate?=?workDate;}/***?@return?the?company*/public?String?getCompany()?{return?company;}/***?@param?company*????????????the?company?to?set*/public?void?setCompany(String?company)?{this.company?=?company;}} public?class?Main?{/***?淺復(fù)制:被復(fù)制對象的所有變量都含有與原來的對象相同的值,而所有的對其他對象的引用都仍然指向原來的對象.*?*?@Description:?TODO*?@param?@param?args*?@return?void*?@throws*/public?static?void?main(String[]?args)?{Resume?a?=?new?Resume("A");a.setPersonalInfo("man",?"28");a.setWorkExperience("2009-2011",?"xx?company");Resume?b?=?(Resume)?a.clone();b.setWorkExperience("2011-2013",?"yy?company");Resume?c?=?(Resume)?a.clone();c.setWorkExperience("2011-2013",?"zz?company");a.dispay();b.dispay();c.dispay();}}

深復(fù)制把引用對象的變量指向復(fù)制過來的新的對象,而不是原來的被引用的對象。

/***?@author?stefanie?zhao*?@date?2014-8-15?下午02:31:04*/ public?class?Resume?implements?Cloneable?{private?String?name;private?String?sex;private?String?age;private?WorkExperience?work;public?Resume(String?name)?{this.name?=?name;work?=?new?WorkExperience();}public?Resume(WorkExperience?work)?{this.work?=?(WorkExperience)?work.clone();}public?void?setPersonalInfo(String?sex,?String?age)?{this.sex?=?sex;this.age?=?age;}public?void?setWorkExperience(String?workDate,?String?company)?{work.setCompany(company);work.setWorkDate(workDate);}public?Object?clone()?{Resume?re?=?new?Resume(this.work);re.setPersonalInfo(this.sex,?this.age);return?re;}public?void?dispay()?{System.out.format("%s?%s?%s",?name,?sex,?age);System.out.format("工作經(jīng)歷:%s?%s",?work.getWorkDate(),?work.getCompany());} } /***?@author?stefanie?zhao*?@date?2014-8-15?下午02:29:23*/ public?class?WorkExperience?implements?Cloneable?{private?String?workDate;private?String?company;/***?@return?the?workDate*/public?String?getWorkDate()?{return?workDate;}/***?@param?workDate*????????????the?workDate?to?set*/public?void?setWorkDate(String?workDate)?{this.workDate?=?workDate;}/***?@return?the?company*/public?String?getCompany()?{return?company;}/***?@param?company*????????????the?company?to?set*/public?void?setCompany(String?company)?{this.company?=?company;}public?Object?clone()?{Object?re?=?null;try?{return?(Object)?super.clone();}?catch?(CloneNotSupportedException?e)?{//?TODO?Auto-generated?catch?blocke.printStackTrace();}return?re;} } public?class?Main?{/***?深復(fù)制把引用對象的變量指向復(fù)制過來的新的對象,而不是原來的被引用的對象。*?*?@Description:?TODO*?@param?@param?args*?@return?void*?@throws*/public?static?void?main(String[]?args)?{Resume?a?=?new?Resume("A");a.setPersonalInfo("man",?"28");a.setWorkExperience("2009-2011",?"xx?company");Resume?b?=?(Resume)?a.clone();b.setWorkExperience("2011-2013",?"yy?company");Resume?c?=?(Resume)?a.clone();c.setWorkExperience("2011-2013",?"zz?company");a.dispay();b.dispay();c.dispay();}}


轉(zhuǎn)載于:https://my.oschina.net/stefanzhlg/blog/308136

總結(jié)

以上是生活随笔為你收集整理的《设计模式系列》---克隆模式的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。