joe boylan david guzman oscar ontiveros fabian pizana jose segura adrian veliz
TRANSCRIPT
![Page 1: Joe Boylan David Guzman Oscar Ontiveros Fabian Pizana Jose Segura Adrian Veliz](https://reader036.vdocument.in/reader036/viewer/2022082713/5697bf7d1a28abf838c8474c/html5/thumbnails/1.jpg)
Data AbstractionJoe Boylan
David GuzmanOscar Ontiveros
Fabian PizanaJose SeguraAdrian Veliz
![Page 2: Joe Boylan David Guzman Oscar Ontiveros Fabian Pizana Jose Segura Adrian Veliz](https://reader036.vdocument.in/reader036/viewer/2022082713/5697bf7d1a28abf838c8474c/html5/thumbnails/2.jpg)
Memento
![Page 3: Joe Boylan David Guzman Oscar Ontiveros Fabian Pizana Jose Segura Adrian Veliz](https://reader036.vdocument.in/reader036/viewer/2022082713/5697bf7d1a28abf838c8474c/html5/thumbnails/3.jpg)
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.
![Page 4: Joe Boylan David Guzman Oscar Ontiveros Fabian Pizana Jose Segura Adrian Veliz](https://reader036.vdocument.in/reader036/viewer/2022082713/5697bf7d1a28abf838c8474c/html5/thumbnails/4.jpg)
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.
![Page 5: Joe Boylan David Guzman Oscar Ontiveros Fabian Pizana Jose Segura Adrian Veliz](https://reader036.vdocument.in/reader036/viewer/2022082713/5697bf7d1a28abf838c8474c/html5/thumbnails/5.jpg)
What does it look like
![Page 6: Joe Boylan David Guzman Oscar Ontiveros Fabian Pizana Jose Segura Adrian Veliz](https://reader036.vdocument.in/reader036/viewer/2022082713/5697bf7d1a28abf838c8474c/html5/thumbnails/6.jpg)
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]
![Page 7: Joe Boylan David Guzman Oscar Ontiveros Fabian Pizana Jose Segura Adrian Veliz](https://reader036.vdocument.in/reader036/viewer/2022082713/5697bf7d1a28abf838c8474c/html5/thumbnails/7.jpg)
Adapter
![Page 8: Joe Boylan David Guzman Oscar Ontiveros Fabian Pizana Jose Segura Adrian Veliz](https://reader036.vdocument.in/reader036/viewer/2022082713/5697bf7d1a28abf838c8474c/html5/thumbnails/8.jpg)
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
![Page 9: Joe Boylan David Guzman Oscar Ontiveros Fabian Pizana Jose Segura Adrian Veliz](https://reader036.vdocument.in/reader036/viewer/2022082713/5697bf7d1a28abf838c8474c/html5/thumbnails/9.jpg)
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
![Page 10: Joe Boylan David Guzman Oscar Ontiveros Fabian Pizana Jose Segura Adrian Veliz](https://reader036.vdocument.in/reader036/viewer/2022082713/5697bf7d1a28abf838c8474c/html5/thumbnails/10.jpg)
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.
![Page 11: Joe Boylan David Guzman Oscar Ontiveros Fabian Pizana Jose Segura Adrian Veliz](https://reader036.vdocument.in/reader036/viewer/2022082713/5697bf7d1a28abf838c8474c/html5/thumbnails/11.jpg)
What does it look like?
![Page 12: Joe Boylan David Guzman Oscar Ontiveros Fabian Pizana Jose Segura Adrian Veliz](https://reader036.vdocument.in/reader036/viewer/2022082713/5697bf7d1a28abf838c8474c/html5/thumbnails/12.jpg)
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
![Page 13: Joe Boylan David Guzman Oscar Ontiveros Fabian Pizana Jose Segura Adrian Veliz](https://reader036.vdocument.in/reader036/viewer/2022082713/5697bf7d1a28abf838c8474c/html5/thumbnails/13.jpg)
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
![Page 14: Joe Boylan David Guzman Oscar Ontiveros Fabian Pizana Jose Segura Adrian Veliz](https://reader036.vdocument.in/reader036/viewer/2022082713/5697bf7d1a28abf838c8474c/html5/thumbnails/14.jpg)
Visitor
![Page 15: Joe Boylan David Guzman Oscar Ontiveros Fabian Pizana Jose Segura Adrian Veliz](https://reader036.vdocument.in/reader036/viewer/2022082713/5697bf7d1a28abf838c8474c/html5/thumbnails/15.jpg)
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
![Page 16: Joe Boylan David Guzman Oscar Ontiveros Fabian Pizana Jose Segura Adrian Veliz](https://reader036.vdocument.in/reader036/viewer/2022082713/5697bf7d1a28abf838c8474c/html5/thumbnails/16.jpg)
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
![Page 17: Joe Boylan David Guzman Oscar Ontiveros Fabian Pizana Jose Segura Adrian Veliz](https://reader036.vdocument.in/reader036/viewer/2022082713/5697bf7d1a28abf838c8474c/html5/thumbnails/17.jpg)
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
![Page 18: Joe Boylan David Guzman Oscar Ontiveros Fabian Pizana Jose Segura Adrian Veliz](https://reader036.vdocument.in/reader036/viewer/2022082713/5697bf7d1a28abf838c8474c/html5/thumbnails/18.jpg)
What does it look like?
![Page 19: Joe Boylan David Guzman Oscar Ontiveros Fabian Pizana Jose Segura Adrian Veliz](https://reader036.vdocument.in/reader036/viewer/2022082713/5697bf7d1a28abf838c8474c/html5/thumbnails/19.jpg)
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]