Skip to content

Add memento pattern with bounded undo/redo for catalog queries#16

Merged
darbyluv2code merged 1 commit intomainfrom
feature/add-memento-pattern
Feb 14, 2026
Merged

Add memento pattern with bounded undo/redo for catalog queries#16
darbyluv2code merged 1 commit intomainfrom
feature/add-memento-pattern

Conversation

@darbyluv2code
Copy link
Owner

Summary

Adds a new implementation demonstrating the Memento pattern with bounded undo/redo functionality. This example shows how to capture and restore object state while maintaining encapsulation.

The implementation includes:

  • Originator class CatalogQueryState that creates and restores snapshots
  • Nested Memento class QuerySnapshot with package-private access for encapsulation
  • Caretaker class CatalogQueryHistory managing bounded undo/redo stacks (max 20 items)
  • Support for complex state including search text, filters, and sort configuration
  • Complete working example with MainApp demonstrating undo/redo operations
  • Deep copying mechanism to prevent state corruption

Technical Details

  • Location: section-04-behavioral-design-patterns/13-memento/
  • Language: Java 24
  • Build tool: Maven
  • Pattern roles: Originator, Memento (nested), Caretaker, Client
  • Key features: Bounded history, deep copying, redo-clearing on new changes

Test Plan

  • Build verification: Maven compilation successful
  • Code follows existing repository patterns and conventions
  • JavaDoc comments present for all classes
  • Demonstrates proper encapsulation with nested Memento class
  • No compilation errors or warnings (excluding JDK version warnings)

@darbyluv2code darbyluv2code merged commit 7d2d945 into main Feb 14, 2026
@darbyluv2code darbyluv2code deleted the feature/add-memento-pattern branch February 14, 2026 19:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant