디자인 모드 비망록 (memento)

더 읽 기
 
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
  • Design.rar (84.4 KB)
  • 다운로드 횟수: 0
  • 좋은 웹페이지 즐겨찾기