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,28 @@
package memento;
/**
* Memento — a snapshot of the editor's state.
* Immutable: once created, the state cannot be changed.
* The Caretaker holds these; the Originator creates and restores from them.
*/
public final class EditorMemento {
private final String content;
private final int cursorPosition;
private final String selectedText;
EditorMemento(String content, int cursorPosition, String selectedText) {
this.content = content;
this.cursorPosition = cursorPosition;
this.selectedText = selectedText;
}
// Package-private: only the Editor (Originator) should read the state back
String getContent() { return content; }
int getCursorPosition() { return cursorPosition; }
String getSelectedText() { return selectedText; }
@Override
public String toString() {
return "Snapshot[content=\"" + content + "\", cursor=" + cursorPosition + "]";
}
}