커맨드 패턴을 사용해 실행과 취소를 캡슐화한 Command 인터페이스와 명령 히스토리를 관리하는 EditorHistory를 구현하세요.
각 명령은 do()와 undo()를 가지며, EditorHistory는 done-스택과 redo-스택을 유지합니다.
export interface Command {
do(): void;
undo(): void;
}
export class EditorHistory {
execute(cmd: Command): void; // cmd.do() 호출 후 done에 push, redo 스택 비움
undo(): boolean; // 되돌릴 명령이 있으면 true, 없으면 false
redo(): boolean; // 다시 할 명령이 있으면 true, 없으면 false
}
const h = new EditorHistory();
h.execute(cmd1);
h.execute(cmd2);
h.undo(); // cmd2.undo() 호출
h.redo(); // cmd2.do() 다시 호출