Jim Fawcett CSE776 – Design Patterns Summer 2005

Slides:



Advertisements
Similar presentations
MicroKernel Pattern Presented by Sahibzada Sami ud din Kashif Khurshid.
Advertisements

Welcome to. Who am I? A better way to code Design Patterns ???  What are design patterns?  How many are there?  How do I use them?  When do I use.
Observer Method 1. References Gamma Erich, Helm Richard, “Design Patterns: Elements of Reusable Object- Oriented Software” 2.
Computer Science 313 – Advanced Programming Topics.
Memento Kendra Kachelein Maureen Thomas. Definition The memento captures and externalizes an object’s internal state, so the object can be restored to.
Software Design & Documentation – Design Pattern: Command Design Pattern: Command Christopher Lacey September 15, 2003.
Memento Page 283 Jason Penny. Memento Behavioral Pattern Behavioral Pattern Intent: Intent: Without violating encapsulation, capture and externalize an.
Behavioral Pattern: Memento C h a p t e r 5 – P a g e 179 Objects frequently expose only some of their internal state using public methods, but there.
Creational Patterns Making Objects The Smart Way Brent Ramerth Abstract Factory, Builder.
Behavioral Patterns C h a p t e r 5 – P a g e 128 BehavioralPatterns Design patterns that identify and realize common interactions between objects Chain.
BDP Behavioral Pattern. BDP-2 Behavioral Patters Concerned with algorithms & assignment of responsibilities Patterns of Communication between Objects.
05 - Patterns Intro.CSC4071 Design Patterns Designing good and reusable OO software is hard. –Mix of specific + general –Impossible to get it right the.
More Design Patterns In Delphi Jim Cooper Falafel Software Session Code: D3.03 Track: Delphi.
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns VII Observer, Command, and Memento.
Behavioral Design Patterns Morteza Yousefi University Of Science & Technology Of Mazandaran 1of 27Behavioral Design Patterns.
Design Patterns CSCI 5801: Software Engineering. Design Patterns.
Software Design Patterns (1) Introduction. patterns do … & do not … Patterns do... provide common vocabulary provide “shorthand” for effectively communicating.
ECE450S – Software Engineering II
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University The Command Pattern.
Design Patterns CSIS 3701: Advanced Object Oriented Programming.
Joe Boylan David Guzman Oscar Ontiveros Fabian Pizana Jose Segura Adrian Veliz.
Behavioral Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Design Pattern Catalog - Page L3-1 PS95&96-MEF-L10-1 Dr. M.E. Fayad Creationa.
CSE 332: Design Patterns Review: Design Pattern Structure A design pattern has a name –So when someone says “Adapter” you know what they mean –So you can.
BEHAVIORAL PATTERNS 13-Sep-2012 Presenters Sanjeeb Kumar Nanda & Shankar Gogada.
A Generalized Architecture for Bookmark and Replay Techniques Thesis Proposal By Napassaporn Likhitsajjakul.
Pattern Bridge. Definition Bridge is the structural pattern that separates abstraction from the implementation so that both of them can be changed independently.
Memento Design Pattern Lee Lisle. Overview Why would we use Memento? Examples of Memento How to implement Memento.
Behavioural Patterns GoF pg Iterator GoF pg. 257 – 271 Memento GoF pg By: Dan Sibbernsen.
The Memento Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
CSE 432: Thanks for the memory leaks, Pushme-Pullyu, and Command Summary of “Thanks for the Memory Leaks” “Left-over” design forces from Type Laundering.
Software Design and Architecture Muhammad Nasir Structural Design Patterns
Overview of Behavioral Patterns ©SoftMoore ConsultingSlide 1.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Command Pattern. Intent encapsulate a request as an object  can parameterize clients with different requests, queue or log requests, support undoable.
File-System Management
Facade Pattern Jim Fawcett CSE776 – Design Patterns Summer 2010
Database Recovery Techniques
Copyright © Jim Fawcett Spring 2017
Abstract Factory Pattern
Factory Method Pattern
Strategy Design Pattern
Strategy Pattern Jim Fawcett CSE776 – Design Patterns Fall 2014.
Event Handling Patterns Asynchronous Completion Token
Software Design Patterns
Behavioral Design Patterns
Chapter 2: System Structures
Observer Design Pattern
Lecture 9- Design Concepts and Principles
Satisfying Open/Closed Principle
Flyweight Design Pattern
Memento Pattern F 羅世東 F 李天彥 F 鄧義佐 F 林尚霖
Memento Design Pattern
Facade Pattern Jim Fawcett CSE776 – Design Patterns Summer 2010
object oriented Principles of software design
Abstract Factory Pattern
What is a Database and Why Use One?
Jim Fawcett CSE776 – Design Patterns Summer 2003
Lecture 9- Design Concepts and Principles
PH Chapter 3 Thanks for the Memory Leaks Pushme-Pullyu (pp
The iterator and memento patterns
Chapter 1 Introduction(1.1)
Ms Munawar Khatoon IV Year I Sem Computer Science Engineering
Strategy Design Pattern
Memento Pattern 1.
Software Design Lecture : 39.
Iterator Design Pattern Jim Fawcett CSE776 – Design Patterns Fall 2014
Message Passing Systems
Strategy Pattern Jim Fawcett CSE776 – Design Patterns Fall 2014.
Presentation transcript:

Jim Fawcett CSE776 – Design Patterns Summer 2005 Memento Pattern Jim Fawcett CSE776 – Design Patterns Summer 2005

References doFactory.com Marc Clifton’s Blog http://www.dofactory.com/Patterns/PatternMemento.aspx Marc Clifton’s Blog http://www.marcclifton.com/tabid/99/Default.aspx Software Architecture, ETH, Zurich Switzerland http://se.ethz.ch/teaching/ss2005/0050/slides/60_softarch_patterns_6up.pdf

Intent Capture and externalize an object’s state without violating encapsulation. Restore the object’s state at some later time. Useful when implementing checkpoints and undo mechanisms that let users back out of tentative operations or recover from errors. Entrusts other objects with the information it needs to revert to a previous state without exposing its internal structure and representations.

Forces Application needs to capture states at certain times or at user discretion. May be used for: Undue / redo Log errors or events Backtracking Need to preserve encapsulation Don’t share knowledge of state with other objects Object owning state may not know when to take state snapshot.

Motivation Many technical processes involve the exploration of some complex data structure. Often we need to backtrack when a particular path proves unproductive. Examples are graph algorithms, searching knowledge bases, and text navigation.

Motivation Memento stores a snapshot of another object’s internal state, exposure of which would violate encapsulation and compromise the application’s reliability and extensibility. A graphical editor may encapsulate the connectivity relationships between objects in a class, whose public interface might be insufficient to allow precise reversal of a move operation. Move Undo

Motivation Memento pattern solves this problem as follows: The editor requests a memento from the object before executing move operation. Originator creates and returns a memento. During undo operation, the editor gives the memento back to the originator. Based on the information in the memento, the originator restores itself to its previous state.

Applicability Use the Memento pattern when: A snapshot of an object’s state must be saved so that it can be restored later, and direct access to the state would expose implementation details and break encapsulation.

Structure

Participants Memento Stores internal state of the Originator object. Originator decides how much. Protects against access by objects other than the originator. Mementos have two interfaces: Caretaker sees a narrow interface. Originator sees a wide interface.

Participants (continued) Originator Creates a memento containing a snapshot of its current internal state. Uses the memento to restore its internal state.

Caretaker Is responsible for the memento’s safekeeping. Never operates on or examines the contents of a memento.

Event Trace

Collaborations A caretaker requests a memento from an originator, holds it for a time, and passes it back to the originator. Mementos are passive. Only the originator that created a memento will assign or retrieve its state.

Consequences Memento has several consequences: Memento avoids exposing information that only an originator should manage, but for simplicity should be stored outside the originator. Having clients manage the state they ask for simplifies the originator.

Consequences (continued) Using mementos may be expensive, due to copying of large amounts of state or frequent creation of mementos. A caretaker is responsible for deleting the mementos it cares for. A caretaker may incur large storage costs when it stores mementos.

Implementation When mementos get created and passed back to their originator in a predictable sequence, then Memento can save just incremental changes to originator’s state.

Known Uses Memento is a 2000 film about Leonard Shelby and his quest to revenge the brutal murder of his wife. Though Leonard is hampered with short-term memory loss, he uses notes and tatoos to compile the information into a suspect.

Known Use of Pattern Dylan language uses memento to provide iterators for its collection facility. Dylan is a dynamic object oriented language using the functional style. Development started by Apple, but subsequently moved to open source.

Related Patterns Command Iterator Mementos can be used for iteration. Commands can use mementos to maintain state for undo mechanisms. Iterator Mementos can be used for iteration.