public class Memento {
public static void main(String[] args){
AnOriginator ao = new AnOriginator();
ao.setA("5");
ao.setB("c");
AMemento am = ao.getAMemento();
ao.setA("3");
ao.setB("i");
System.out.println(ao.getA()+ao.getB());
System.out.println(am.getA()+am.getB());
}
}
class AnOriginator{
private String a;
private String b;
public AMemento getAMemento(){
return new AMemento(this);
}
public String getA() {
return a;
}
public void setA(String a) {
this.a = a;
}
public String getB() {
return b;
}
public void setB(String b) {
this.b = b;
}
}
class AMemento{
private String a;
private String b;
public AMemento(AnOriginator anOriginator){
this.a = anOriginator.getA();
this.b = anOriginator.getB();
}
public String getA() {
return a;
}
public void setA(String a) {
this.a = a;
}
public String getB() {
return b;
}
public void setB(String b) {
this.b = b;
}
}
//http://zuoqiang.iteye.com/blog/744024