19
Data Abstraction Joe Boylan David Guzman Oscar Ontiveros Fabian Pizana Jose Segura Adrian Veliz

Joe Boylan David Guzman Oscar Ontiveros Fabian Pizana Jose Segura Adrian Veliz

Embed Size (px)

Citation preview

Page 1: Joe Boylan David Guzman Oscar Ontiveros Fabian Pizana Jose Segura Adrian Veliz

Data AbstractionJoe Boylan

David GuzmanOscar Ontiveros

Fabian PizanaJose SeguraAdrian Veliz

Page 2: Joe Boylan David Guzman Oscar Ontiveros Fabian Pizana Jose Segura Adrian Veliz

Memento

Page 3: Joe Boylan David Guzman Oscar Ontiveros Fabian Pizana Jose Segura Adrian Veliz

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

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

What does it look like

Page 6: Joe Boylan David Guzman Oscar Ontiveros Fabian Pizana Jose Segura Adrian Veliz

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

Adapter

Page 8: Joe Boylan David Guzman Oscar Ontiveros Fabian Pizana Jose Segura Adrian Veliz

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

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

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

What does it look like?

Page 12: Joe Boylan David Guzman Oscar Ontiveros Fabian Pizana Jose Segura Adrian Veliz

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 14: Joe Boylan David Guzman Oscar Ontiveros Fabian Pizana Jose Segura Adrian Veliz

Visitor

Page 15: Joe Boylan David Guzman Oscar Ontiveros Fabian Pizana Jose Segura Adrian Veliz

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

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

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

What does it look like?

Page 19: Joe Boylan David Guzman Oscar Ontiveros Fabian Pizana Jose Segura Adrian Veliz

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]