Design pattern of the day – Memento

Definition and use case from (

Memento is a Behavioral Pattern( Used to manage algorithms, relationships, and responsibilities between objects ) .

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.
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.

Or visit our main page


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s