![這裏寫圖片描述]()
![這裏寫圖片描述]()
代碼實現
/**
* 源發器類
* @author Administrator
*
*/
public class Emp {
private String ename;
private int age;
private double salary;
public EmpMemento memento(){
return new EmpMemento(this);
}
public void recovery(EmpMemento mmt){
this.ename = mmt.getEname();
this.age = mmt.getAge();
this.salary = mmt.getSalary();
}
public Emp(String ename, int age, double salary) {
super();
this.ename = ename;
this.age = age;
this.salary = salary;
}
public String getEname() {
return ename;
}
public void setEname(String ename) {
this.ename = ename;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
}
/**
* 備忘錄類
* @author Administrator
*
*/
public class EmpMemento {
private String ename;
private int age;
private double salary;
public EmpMemento(Emp e) {
this.ename = e.getEname();
this.age = e.getAge();
this.salary = e.getSalary();
}
public String getEname() {
return ename;
}
public void setEname(String ename) {
this.ename = ename;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
}
/**
* 負責人類
* 負責管理備忘錄對象
* @author Administrator
*
*/
public class CareTaker {
private EmpMemento memento;
public EmpMemento getMemento() {
return memento;
}
public void setMemento(EmpMemento memento) {
this.memento = memento;
}
}
![這裏寫圖片描述]()
多個備忘點
![這裏寫圖片描述]()
![這裏寫圖片描述]()
![這裏寫圖片描述]()