Data AbstractionJoe Boylan
David GuzmanOscar Ontiveros
Fabian PizanaJose SeguraAdrian Veliz
Memento
What is MementoThe 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 workMemento 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.
What does it look like
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]
Adapter
What is it and what does it do?Translates an interface for one class into a
compatible interface expected by anotherAllows classes to work together that usually
could not have because of incompatible interfaces
Support legacy componentsA 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/YYYYA new component has its date in the form
YYYYMMDDThe Adapter will simply translate the call
from the new class into a compatible call to the original and vice-versa
Properties of AdapterThe Adapter class “has a” instance of the
adaptee classThe adapter class “maps” the client interface
to the adaptee interfaceThe client uses (is coupled to) the new
interface.
What does it look like?
Adapter vs. FacadeBoth designs are similarFacade is used when we want to simplify or
make another interface easier to work withAdapter 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
Referenceshttp://en.wikipedia.org/wiki/Adapter_patternhttp://www.cs.mcgill.ca/~adenau/teaching/cs
303/lecture19.pdfhttp://www.kim-team.com/blog/wp-content/up
loads/2009/01/adapter.gifhttp://sourcemaking.com/design_patterns/ada
pter
Visitor
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 classesA 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 argumentThe accept method calls back the visit
method to perform new operationsThis way the concrete visitor classes can be
added to perform particular operations without modifying or affecting particular element classes
Properties of VisitorEncapsulates an operation to be performed
on the elements of a data structureIts intent is to decouple algorithm and classes
for the data structureMapper function to traverse a particular type
of object and apply a function to its elements
What does it look like?
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]