190 likes | 227 Views
Data Abstraction. Joe Boylan David Guzman Oscar Ontiveros Fabian Pizana Jose Segura Adrian Veliz. Memento . What is Memento. The memento pattern gives software the ability to encapsulate the current state of a program in order for it to be later restored. . How does it work.
E N D
Data Abstraction Joe Boylan David Guzman Oscar Ontiveros Fabian Pizana Jose Segura Adrian Veliz
What is Memento • The memento pattern gives software the ability to encapsulate the current state of a program in order for it to be later restored.
How does it work • Memento allows you to have a state that stores information about the current program, enough so that it’s possible to roll back to a previous state and resume work. This is useful if you would like for a program to allow the user to recover from a mistake, or undo one or a series of actions. This is done by having 3 objects Memento, Originator, & Caretaker. Memento represents the internal state of the program. The originator is the one that create the current state by calling the Memento constructor. The caretaker asks the originator for a state. It then allows the user to work with the state provided by the caretaker. However the originator state itself is not modified, this is so it’s possible to rollback. This is done by having the originator set a given state as the Memento.
References • [1] Wikimedia Foundation, Inc. Memento pattern. Internet: http://en.wikipedia.org/wiki/Memento_pattern [1/28/2011] • [2]Dan Adams. Memento Pattern Internet: http://web.cs.wpi.edu/~gpollice/cs509-s04/Patterns/memento.html [1/28/2011]
What is it and what does it do? • Translates an interface for one class into a compatible interface expected by another • Allows classes to work together that usually could not have because of incompatible interfaces • Support legacy components • A call to the Adapter’s interface translates to a call to the original interface
How does it do it? • An original interface may be expecting a date in the form MM/DD/YYYY • A new component has its date in the form YYYYMMDD • The Adapter will simply translate the call from the new class into a compatible call to the original and vice-versa
Properties of Adapter • The Adapter class “has a” instance of the adaptee class • The adapter class “maps” the client interface to the adaptee interface • The client uses (is coupled to) the new interface.
Adapter vs. Facade • Both designs are similar • Facade is used when we want to simplify or make another interface easier to work with • Adapter is used when we directly need to use an interface with another class whose interaction is not directly compatible • Facade defines a new interface, Adapter reuses an old interface
References • http://en.wikipedia.org/wiki/Adapter_pattern • http://www.cs.mcgill.ca/~adenau/teaching/cs303/lecture19.pdf • http://www.kim-team.com/blog/wp-content/uploads/2009/01/adapter.gif • http://sourcemaking.com/design_patterns/adapter
What is it and what does it do? • Design pattern that uses a Visitor class to implement new operations to existing object structures • Does not require modifying existing classes • A call to the Visitors’ interface controls which visitor method to be invoked
How does it do it? • The element structure uses the accept method with the visitor object as argument • The accept method calls back the visit method to perform new operations • This way the concrete visitor classes can be added to perform particular operations without modifying or affecting particular element classes
Properties of Visitor • Encapsulates an operation to be performed on the elements of a data structure • Its intent is to decouple algorithm and classes for the data structure • Mapper function to traverse a particular type of object and apply a function to its elements
References • [1] Wikimedia Foundation, Inc. Visitor pattern. Internet: http://en.wikipedia.org/wiki/Visitor_pattern [1/28/2011] • [2] Antonio García. The Visitor Design Pattern Internet:http://www.exciton.cs.rice.edu/javaresources/designpatterns/VisitorPattern.htm [1/28/2011]