1 / 19

Data Abstraction

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.

ewa
Download Presentation

Data Abstraction

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. Memento

  3. 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.

  4. 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.

  5. What does it look like

  6. 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]

  7. Adapter

  8. 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

  9. 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

  10. 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.

  11. What does it look like?

  12. 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

  13. 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

  14. Visitor

  15. 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

  16. 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

  17. 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

  18. What does it look like?

  19. 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]

More Related