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,40 @@
package command;
/**
* Command Design Pattern — Runnable Demo
* Run: javac command/*.java -d out/command && java -cp out/command command.Main
* Article: https://ankurm.com/command-design-pattern-java/
*/
public class Main {
public static void main(String[] args) {
System.out.println("=== Command Design Pattern Demo ===\n");
TextEditor editor = new TextEditor();
CommandHistory history = new CommandHistory();
System.out.println("Initial: " + editor);
history.execute(new InsertCommand(editor, "Hello", 0));
System.out.println("After: " + editor);
history.execute(new InsertCommand(editor, " World", 5));
System.out.println("After: " + editor);
history.execute(new DeleteCommand(editor, 5, 6));
System.out.println("After: " + editor);
System.out.println("\n-- Undo sequence --");
history.undo();
System.out.println("After undo: " + editor);
history.undo();
System.out.println("After undo: " + editor);
history.undo();
System.out.println("After undo: " + editor);
history.undo(); // nothing left
System.out.println("\n=== Demo complete ===");
}
}