Skip to content

Add RealWorld example for the Memento pattern #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions src/RefactoringGuru/Memento/RealWorld/Output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
=== Text Editor with Memento Pattern Demo ===

1. Initial state:
Content: '' | Cursor: 0 | Selected: '' | Format: {"bold":false,"italic":false,"fontSize":12}

State saved to history (index: 0)


2. Typing 'Hello World':
Typed: 'Hello World' | Content: 'Hello World'
State saved to history (index: 1)


3. Applying bold formatting:
Applied formatting: {"bold":true}
State saved to history (index: 2)
Named snapshot 'hello_world_bold' saved


4. Adding more text:
Typed: ' - This is amazing!' | Content: 'Hello World - This is amazing!'
State saved to history (index: 3)


5. Deleting some text:
Deleted: 's amazing!' | Content: 'Hello World - This i'
State saved to history (index: 4)

=== Editor History ===
[0] 2025-07-16 18:52:48 - "" (pos: 0)
[1] 2025-07-16 18:52:48 - "Hello World" (pos: 11)
[2] 2025-07-16 18:52:48 - "Hello World" (pos: 11)
[3] 2025-07-16 18:52:48 - "Hello World - This i..." (pos: 30)
-> [4] 2025-07-16 18:52:48 - "Hello World - This i" (pos: 20)
======================



6. Undo operations:
State restored | Content: 'Hello World - This is amazing!' | Cursor: 30
Undo successful
State restored | Content: 'Hello World' | Cursor: 11
Undo successful


7. Redo operation:
State restored | Content: 'Hello World - This is amazing!' | Cursor: 30
Redo successful

=== Editor History ===
[0] 2025-07-16 18:52:48 - "" (pos: 0)
[1] 2025-07-16 18:52:48 - "Hello World" (pos: 11)
[2] 2025-07-16 18:52:48 - "Hello World" (pos: 11)
-> [3] 2025-07-16 18:52:48 - "Hello World - This i..." (pos: 30)
[4] 2025-07-16 18:52:48 - "Hello World - This i" (pos: 20)
======================



8. Named snapshots:

=== Named Snapshots ===
'hello_world_bold' - 2025-07-16 18:52:48 - "Hello World" (pos: 11)
========================



9. Restoring from named snapshot:
State restored | Content: 'Hello World' | Cursor: 11
Restored from named snapshot 'hello_world_bold'


10. Final state:
Content: 'Hello World' | Cursor: 11 | Selected: '' | Format: {"bold":true,"italic":false,"fontSize":12}

Loading