Add all 23 GoF design pattern implementations

This commit is contained in:
2026-07-25 10:50:29 +05:30
commit f5688a6b32
164 changed files with 4371 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(); }
}