Design pattern of the day - Memento

Solution Architect - 15 November 2017 - 12min
Solution Architect - 15 November 2017 - 12min
Definition and use case from (https://dzone.com/refcardz/design-patterns)
Memento is a Behavioral Pattern( Used to manage algorithms, relationships, and responsibilities between objects ) .
Purpose
Allows for capturing and externalizing an object’s internal state so that it can be restored later, all without violating encapsulation.
Use When
• The internal state of an object must be saved and restored at a later time.
• Internal state cannot be exposed by interfaces without exposing implementation.
• Encapsulation boundaries must be preserved.
Example
Undo functionality can nicely be implemented using the memento pattern. By serializing and deserializing the state of an object before the change occurs we can preserve a snapshot of it that can later be restored should the user choose to undo the operation
How we are using memento in node-data
on every transaction api we provide an way for user to undo changes using entity manager
export interface EntityActionParam { inputEntity?: any; oldPersistentEntity?: any; newPersistentEntity?: any }
using the manager you can always receive the input entity any where in the object execution cycle , allowing a developer to instantly rollback the transaction .
in Node-Data we have used memento in many places, If you want to know more about node-data check out the our github.
https://github.com/ratneshsinghparihar/Node-Data
Or visit our main page
https://nodedataio.azurewebsites.net/
Leave a Reply