Add all 23 GoF design pattern implementations (2026-06-13)

This commit is contained in:
Ankur
2026-06-13 21:44:56 +05:30
commit a5beb61425
106 changed files with 2977 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
package memento;
import java.util.ArrayDeque;
import java.util.Deque;
/**
* Caretaker — manages the stack of mementos.
* It does NOT open or inspect the mementos; it just stores and returns them.
*/
public class History {
private final Deque<EditorMemento> snapshots = new ArrayDeque<>();
public void save(EditorMemento memento) {
snapshots.push(memento);
System.out.println(" [History] Saved: " + memento);
}
public EditorMemento undo() {
if (snapshots.isEmpty()) return null;
return snapshots.pop();
}
public int size() { return snapshots.size(); }
}