Big talk Design Pattern _ prototype Pattern

Source: Internet
Author: User

Here is an example of copying a resume.

Package COM. WZS. design;/*** big talk design mode -- page88 prototype mode ** @ author administrator **/public class prototypepattern {public static void main (string [] ARGs) throws clonenotsupportedexception {workexperience = new workexperience ("2011-2-2", "2013-3-3", ""); resume a = New resume ("", "male ", "23", workexperience); resume B = (resume). clone (); workexperience workexperience2 = new workexperience ("2011-2-2", "2013-3-3", "Google China"); B. setworkexperience (workexperience2); resume c = (resume). clone (); C. setage ("99");. display (); B. display (); C. display () ;}/ ** resume */class resume implements cloneable {private string name; private string sex; private string age; private workexperience; public resume (string name, string sex, string age, workexperience) {This. name = Name; this. sex = sex; this. age = age; this. workexperience = workexperience;} public void display () {system. out. println ("name:" + name + "Sex:" + sex + "Age:" + age + "" + workexperience) ;}@ overrideprotected object clone () throws clonenotsupportedexception {return Super. clone ();} Public String getname () {return name;} public void setname (string name) {This. name = Name;} Public String getsex () {return sex;} public void setsex (string sex) {This. sex = sex;} Public String getage () {return age;} public void setage (string age) {This. age = age;} public workexperience getworkexperience () {return workexperience;} public void setworkexperience (workexperience) {This. workexperience = workexperience;}/** work experience */class workexperience {private string workdatastart; // work start time private string workdataend; // work end time private string company; // company public workexperience (string workdatastart, string workdataend, string Company) {This. workdatastart = workdatastart; this. workdataend = workdataend; this. company = company;} Public String getworkdatastart () {return workdatastart;} public void setworkdatastart (string workdatastart) {This. workdatastart = workdatastart;} Public String getworkdataend () {return workdataend;} public void setworkdataend (string workdataend) {This. workdataend = workdataend;} Public String getcompany () {return company;} public void setcompany (string Company) {This. company = company ;}@ overridepublic string tostring () {return "Start Time:" + workdatastart + "End Time:" + workdataend + "company name:" + company ;}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.