Questions tagged [memento]

The Memento pattern allows a caretaker object to roll back the originator object to a previous state, offering undo capability. It is one of the Gang of Four's behavioral design patterns.

This is one of the Gang of Four's behavioral , first published in Gamma et al.'s book "Design Patterns: Elements of Reusable Object-Oriented Software".

More information is available on Wikipedia.

75 questions
32
votes
8 answers

How to implement good and efficient undo/redo functionality for a TextBox

I have a TextBox which I would like to implement undo/redo functionality for. I have read that it might have some slight undo functionality already, but that it is buggy? Anyways, I would like to implement both undo and redo functionality also just…
Svish
  • 152,914
  • 173
  • 462
  • 620
17
votes
4 answers

Difference between Memento Pattern and Serialization

I am doing some research into the Memento Pattern and I am generally new to behavioural patterns and with my research I have been getting pretty confused. One of the main things I have been getting confused on is the differences between the Memento…
Mr. Espresso
  • 261
  • 4
  • 12
16
votes
4 answers

How is the Memento Pattern implemented in C#4?

The Memento Pattern itself seems pretty straight forward. I'm considering implementing the same as the wikipedia example, but before I do are there any language features of C# that make it easier to implement or use?
Dave Hillier
  • 18,105
  • 9
  • 43
  • 87
9
votes
3 answers

State Pattern C# with previous states

I am new to the state pattern implementation in C#, could you provide some info on how you implement it. I am refactoring a state machine in C# using the state pattern. Currently my state machine contains 5 states and it is only possible to go…
Manolete
  • 3,431
  • 7
  • 54
  • 92
8
votes
3 answers

How is java.io.Serializable the Memento pattern?

As we know the memento pattern is without violating encapsulation, capturing and externalize a object's internal state and can be reclaimed later without knowledge of the orginal state. My question comes here how java.io.Serializable is coming…
BOSS
  • 2,931
  • 8
  • 28
  • 53
8
votes
3 answers

What are some design patterns for doing version control of an object?

What are some design patterns for keeping a history of an object as it changes. I don't need anything as heavy duty as event sourcing, just the ability to save past versions when a specific event happens (in this case when a print form button is…
George Mauer
  • 117,483
  • 131
  • 382
  • 612
7
votes
1 answer

Why we need Caretaker class in Memento Pattern? Is it really so important?

I currently trying to figure out how Memento Pattern works. And I stuck with Caretaker class? Is it really important to have it? I mean I can use Memento without this class. Please see my code below. public class Originator { private String…
barbara
  • 3,111
  • 6
  • 30
  • 58
6
votes
3 answers

What is the difference between Memento and Command design pattern?

I have successfully coded a solitaire game on Java, and now I have been asked to implement an undo/redo on top of my design. My plan was to store a list or stack of moves the user executed, and if the user wants to undo, I would 1. check if the user…
B.M. Corwen
  • 205
  • 3
  • 10
6
votes
3 answers

Memento design pattern and State design pattern

Memento design pattern is used for restoring objects to previous state, like undo. But we can do undo and redo multiple times. I have read articles multiple times but still unclear to me as to are they similar or complement each other and can be…
Narendra Pathai
  • 41,187
  • 18
  • 82
  • 120
5
votes
2 answers

Memento in Javascript

I'm looking for a JavaScript implementation of the memento pattern (GoF) to be used in CRUD forms. In its basic level it will be enough to undo changes on inputs, but it would be great to use it with standard JS frameworks like YUI or Ext, to undo &…
Lluis Martinez
  • 1,963
  • 8
  • 28
  • 42
5
votes
1 answer

How to use the memento design pattern to save the state of multiple objects?

I'm very confused about how the memento is supposed to be implemented. I understand the Memento has a State. And the Memento Pattern is used to store different (previous) states so that one can restore an object to previous states, Well lets say I…
Jose V
  • 1,655
  • 1
  • 17
  • 31
4
votes
3 answers

Eclipse call ViewPart saveState on View close

I have a Eclipse plugin that uses a view which extends ViewPart. ViewPart has a saveState method which requires an IMemento. I added my code to saveState and the corresponding init method and it works. Unfortunately, saveState is only called if the…
user867204
  • 265
  • 4
  • 16
4
votes
2 answers

Correct implementation of Memento

With the memento design pattern, is it wrong to have the Caretaker as an aggregate of the Originator?
Dan
  • 17,375
  • 3
  • 36
  • 39
4
votes
2 answers

Storing the state of a complex object with Memento pattern (and Command)

I'm working on a small UML editor project, in Java, that I started a couple of months ago. After a few weeks, I got a working copy for a UML class diagram editor. But now, I'm redesigning it completely to support other types of diagrams, such a…
Guillaume Gervais
  • 1,035
  • 2
  • 14
  • 26
3
votes
2 answers

Implements undoable command - Java

I'm currently programming a little text editor (project for school) and I'm having some troubles finding a good and clean way to manage the undoable commands. (It is not a code review question as it's not only about improvement. I need to change my…
talnicolas
  • 13,885
  • 7
  • 36
  • 56
1
2 3 4 5