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,28 @@
package command;
import java.util.ArrayDeque;
import java.util.Deque;
/**
* Invoker — holds command history and triggers execute/undo.
* It doesn't know what the commands do; it just calls execute() and undo().
*/
public class CommandHistory {
private final Deque<Command> history = new ArrayDeque<>();
public void execute(Command cmd) {
cmd.execute();
history.push(cmd);
System.out.println(" Executed: " + cmd.getDescription());
}
public void undo() {
if (history.isEmpty()) {
System.out.println(" Nothing to undo.");
return;
}
Command cmd = history.pop();
cmd.undo();
System.out.println(" Undone: " + cmd.getDescription());
}
}