public
class
Resume
implements
Cloneable{
String name;
String sex;
String age;
String timearea;
String company;
public
Resume(String name)
{
super();
this.name = name;
}
public
Resume()
{
super();
}
//设置个人信息
public
void setPersonInfo(String sex,String age){
this.sex = sex;
this.age = age;
}
//设置个人信息
public
void setWorkExperience(String timearea,String company){
this.timearea = timearea;
this.company = company;
}
@Override
public
String toString()
{
return name +
" "
+ sex +
" "
+ age +
"\n工作经历:"
+ timearea +
" "
+ company;
}
public
Object
Clone()
throws
Exception{
return
this.clone();
}
}
public
class
Test
{
public
static
void main(String[] args)
throws
Exception
{
Resume a =
new
Resume("大鸟");
a.setPersonInfo("男",
"20岁");
a.setWorkExperience("2013-2017",
"东北林业大学");
Resume b =
(Resume)a.Clone();
b.setWorkExperience("2017-2022",
"哈尔滨工业大学");
Resume c =
(Resume)a.Clone();
c.setWorkExperience("2022-2030",
"google");
System.out.println(a);
System.out.println(b);
System.out.println(c);
}
}
大鸟
男
20岁
工作经历:2013-2017
东北林业大学
大鸟
男
20岁
工作经历:2017-2020
哈尔滨工业大学
大鸟
男
20岁
工作经历:2020-2022 google
public
class
WorkExperience
{
String timearea;
String company;
public
String getTimearea()
{
return timearea;
}
public
void setTimearea(String timearea)
{
this.timearea = timearea;
}
public
String getCompany()
{
return company;
}
public
void setCompany(String company)
{
this.company = company;
}
@Override
public
String toString()
{
return
"\n工作经历"
+ timearea +
" "
+ company;
}
}
public
class
Resume
implements
Cloneable{
String name;
String sex;
String age;
WorkExperience work;
public
Resume(String name)
{
super();
this.name = name;
work =
new
WorkExperience();
}
public
Resume()
{
super();
}
//设置个人信息
public
void setPersonInfo(String sex,String age){
this.sex = sex;
this.age = age;
}
public
void setWorkExperience(String timearea,String company){
work.timearea = timearea;
work.company = company;
}
@Override
public
String toString()
{
return name +
" "
+ sex +
" "
+ age + work ;
}
public
Object
Clone()
throws
Exception{
return
this.clone();
}
}
大鸟
男
20岁
工作经历:2020-2022 google
大鸟
男
20岁
工作经历:2020-2022 google
大鸟
男
20岁
工作经历:2020-2022 google
public
class
WorkExperience
implements
Cloneable{
String timearea;
String company;
public
String getTimearea()
{
return timearea;
}
public
void setTimearea(String timearea)
{
this.timearea = timearea;
}
public
String getCompany()
{
return company;
}
public
void setCompany(String company)
{
this.company = company;
}
@Override
public
String toString()
{
return
"\n工作经历"
+ timearea +
" "
+ company;
}
public
Object
Clone()
throws
Exception{
return
this.clone();
}
}
public
class
Resume
implements
Cloneable{
String name;
String sex;
String age;
WorkExperience work;
public
Resume(String name)
{
super();
this.name = name;
work =
new
WorkExperience();
}
public
Resume()
{
super();
}
private
Resume(WorkExperience work)
throws
Exception
{
super();
this.work =
(WorkExperience)work.Clone();
}
//设置个人信息
public
void setPersonInfo(String sex,String age){
this.sex = sex;
this.age = age;
}
public
void setWorkExperience(String timearea,String company){
work.timearea = timearea;
work.company = company;
}
@Override
public
String toString()
{
return name +
" "
+ sex +
" "
+ age + work ;
}
public
Object
Clone()
throws
Exception{
Resume obj =
new
Resume(this.work);
obj.name =
this.name;
obj.age =
this.age;
obj.sex =
this.sex;
return obj;
}
}
大鸟
男
29岁
工作经历2013-2017
东北林业大学
大鸟
男
29岁
工作经历2017-2022
哈尔滨工业大学
大鸟
男
29岁
工作经历2020-2030 google
往期回顾
设计模式(一) | 啥是工厂模式和策略模式?
设计模式(二) | 装饰模式---穿什么有这么重要?
设计模式(三) | 为别人做嫁衣---代理模式