SlideShare a Scribd company logo
1 of 9
Download to read offline
MEMENTO PATTERN
INTENT 
• Is to capture the internal state of an object without violating encapsulation and thus 
providing a man for restoring the object into initial state when needed.
UML CLASS DIAGRAM
• Memento 
• Stores internal state of the Originator object. 
• It must have two interfaces, one for the caretaker – this interface must not allow nay 
operation or any access to internal state stored by the memento and thus honors 
encapsulation. The other interface is to the originator and allows the originator to 
access any state variables necessary to for the originator to restore previous state. 
• Originator 
• Creates a memento object capturing the originators internal state 
• Uses the memento object to restore its previous state 
• Caretaker 
• Responsible for keeping the memento 
• The memento is opaque to the caretaker, and the caretaker must not operate on it.
APPLICABILITY AND EXAMPLES 
• Is used when a snapshot of an object’s state must be captured so that it can be restored 
to that state later and in situations where explicitly passing the state of the object would 
violate encapsulation. 
• http://www.oodesign.com/memento-pattern-calculator-example-java-sourcecode.html
SPECIFIC PROBLEMS AND IMPLEMENTATION 
• Database Transactions 
The mechanism of transaction rolling back use the memento design pattern. Consider an 
object representing a db table, a transaction manager object which is responsible of 
performing transactions must perform operations on the table object while having the 
ability undo the operation if it or any operations fails. To be able to rollback, the 
transaction manager object would ask the table object for a memento before performing 
an operation and thus in case of failure, the memento object would be used to restore 
the table to its previous state.
CONSEQUENCES 
• Protects encapsulation and avoids exposing originator’s internal state and 
implementation. It also simplifies originator code such that the originator does not need to 
keep track of its previous state since this is the responsibility of the caretaker. 
• Using the memento can be expensive depending on the amount of state information that 
has to be stored inside the memento object. In addition the caretaker must contain 
additional logic to be able to manage mementos.
RULES OF THUMB 
• Command and Memento act as magic tokens to be passed around and invoked at a later 
time. In command, the token represents a request; in memento, it represents the internal 
state of an object at a particular time. Polymorphism is important to Command, but not to 
Memento since its interface is so narrow that it can only be passed as a value. 
• Command can use Memento to maintain the state required for an undo operation. 
• Memento is often used in conjunction with Iterator. An Iterator can use a Memento to 
capture the state of an iteration.
REFERENCES 
• http://sourcemaking.com/design_patterns/memento 
• http://www.oodesign.com/memento-pattern.html

More Related Content

Featured

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationErica Santiago
 

Featured (20)

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 

Memento

  • 2. INTENT • Is to capture the internal state of an object without violating encapsulation and thus providing a man for restoring the object into initial state when needed.
  • 4. • Memento • Stores internal state of the Originator object. • It must have two interfaces, one for the caretaker – this interface must not allow nay operation or any access to internal state stored by the memento and thus honors encapsulation. The other interface is to the originator and allows the originator to access any state variables necessary to for the originator to restore previous state. • Originator • Creates a memento object capturing the originators internal state • Uses the memento object to restore its previous state • Caretaker • Responsible for keeping the memento • The memento is opaque to the caretaker, and the caretaker must not operate on it.
  • 5. APPLICABILITY AND EXAMPLES • Is used when a snapshot of an object’s state must be captured so that it can be restored to that state later and in situations where explicitly passing the state of the object would violate encapsulation. • http://www.oodesign.com/memento-pattern-calculator-example-java-sourcecode.html
  • 6. SPECIFIC PROBLEMS AND IMPLEMENTATION • Database Transactions The mechanism of transaction rolling back use the memento design pattern. Consider an object representing a db table, a transaction manager object which is responsible of performing transactions must perform operations on the table object while having the ability undo the operation if it or any operations fails. To be able to rollback, the transaction manager object would ask the table object for a memento before performing an operation and thus in case of failure, the memento object would be used to restore the table to its previous state.
  • 7. CONSEQUENCES • Protects encapsulation and avoids exposing originator’s internal state and implementation. It also simplifies originator code such that the originator does not need to keep track of its previous state since this is the responsibility of the caretaker. • Using the memento can be expensive depending on the amount of state information that has to be stored inside the memento object. In addition the caretaker must contain additional logic to be able to manage mementos.
  • 8. RULES OF THUMB • Command and Memento act as magic tokens to be passed around and invoked at a later time. In command, the token represents a request; in memento, it represents the internal state of an object at a particular time. Polymorphism is important to Command, but not to Memento since its interface is so narrow that it can only be passed as a value. • Command can use Memento to maintain the state required for an undo operation. • Memento is often used in conjunction with Iterator. An Iterator can use a Memento to capture the state of an iteration.
  • 9. REFERENCES • http://sourcemaking.com/design_patterns/memento • http://www.oodesign.com/memento-pattern.html