当前位置:首页 > 开发 > 系统架构 > 架构 > 正文

设计模式之备忘录(memento)

发表于: 2011-07-14   作者:edwin492   来源:转载   浏览:
摘要:   public class Memento { public static void main(String[] args){ AnOriginator ao = new AnOriginator(); ao.setA("5"); ao.setB("c"); AMemento am = ao.getAMemento(

 

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

设计模式之备忘录(memento)

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号