设计模式之备忘录(memento)
程序员文章站
2022-05-03 21:39:50
...
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
上一篇: SVG自整理
下一篇: php实现简单爬虫的开发,php实现爬虫