메멘토 패턴: 두 판 사이의 차이
내용 삭제됨 내용 추가됨
새 문서: '''메멘토 패턴'''(memento pattern)은 객체를 이전 상태로 되돌릴 수 있는 기능을 제공하는 소프트웨어 디자인 패턴이다. (롤백을 통한 실... |
잔글 봇: 틀 이름 및 스타일 정리 |
||
6번째 줄:
== 개요 ==
메멘토<ref name="GoF">{{
== 구조 ==
=== UML 클래스 및 시퀀스 다이어그램 ===
[[
== 예시 ==
21번째 줄:
// The class could also contain additional data that is not part of the
// state saved in the memento..
public void set(String state) {
this.state = state;
System.out.println("Originator: Setting state to " + state);
}
public Memento saveToMemento() {
System.out.println("Originator: Saving to Memento.");
return new Memento(this.state);
}
public void restoreFromMemento(Memento memento) {
this.state = memento.getSavedState();
System.out.println("Originator: State after restoring from Memento: " + state);
}
public static class Memento {
private final String state;
43번째 줄:
state = stateToSave;
}
// accessible by outer class only
private String getSavedState() {
50번째 줄:
}
}
class Caretaker {
public static void main(String[] args) {
List<Originator.Memento> savedStates = new ArrayList<Originator.Memento>();
Originator originator = new Originator();
originator.set("State1");
63번째 줄:
savedStates.add(originator.saveToMemento());
originator.set("State4");
originator.restoreFromMemento(savedStates.get(1));
}
}
|