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
3
votes
2 answers

What does "without violating encapsulation" mean in Memento pattern

Wikipedia's description of the Memento pattern states that: The internal state of an object should be saved externally so that the object can be restored to this state later. The object's encapsulation must not be violated. I'm confused as to…
lynxx
  • 544
  • 3
  • 18
3
votes
1 answer

Memento pattern drawbacks

So, here is an typical implementation of Memento pattern (skipped getters and setters). public class Employee { private String name; private String phone; public EmployeeMemento save() { return new EmployeeMemento(name, phone); …
3
votes
4 answers

Memento implementation on .NET

I've seen two different implementation of memento on .NET. One is pretty straightforward - The object creates another instance of itself. The other is serializing the object using BinaryFormatter and MemoryStream. Which is the preferred method? Can…
Jiho Han
  • 1,610
  • 1
  • 19
  • 41
3
votes
5 answers

Save and load objects without breaking encapsulation

I want to save and load objects to a database without using a ORM (like Hibernate). Lets say i have the following class: public class Person { private int age; public void birthday(){ age++; } } This class doesn't provide a…
Aeon
  • 87
  • 1
  • 11
3
votes
2 answers

memento pattern - restore complex object in a memento (JAVA)

Thank you for reading this question. Please help me to solve this complex issue. Here is the situation: Oringator holds a object to execute some method. Memento pattern needs to backup the complex object state in oringator.How? Example…
3
votes
2 answers

Different ways to implement the Memento Pattern in Java

I am doing some research into the Memento Pattern and it seems that most of the examples I have come across seem to be relatively similar (Saving a String into an array and restoring it when needed) now correct me if I am wrong but I believe the…
Mr. Espresso
  • 261
  • 4
  • 12
2
votes
1 answer

Qt C++ Memento Design Pattern, I am trying to add a Undo/Redo function to my program, but why doesn't it work properly?

I am learning about the Memento Design Pattern and have constructed a simple Program for this purpose. I have constructed 2 classes, Container, which only holds a QString called Code The GUI is very simple, there is a QListWidget that displays a…
2
votes
2 answers

DTO pattern vs Memento pattern

What are the differences between DTO pattern(by Fowler) and Memento pattern(by GoF) in motivation and implementation aspect? Can it be the same classes? If yes, how can I name them (xxxDTO or xxxMemento)? Do they have any principal difference in…
Stan Kurilin
  • 15,614
  • 21
  • 81
  • 132
2
votes
1 answer

Domain Model Snapshot for Mapping and Reconstitution using Factory

I've read in the Patterns, Principles and Practices of DDD book that if you want to fully encapsulate your domain model you can make its properties private and use the Memento pattern to read them. There was also an example that a Repository gets a…
QuietNaN
  • 371
  • 1
  • 14
2
votes
1 answer

persistence of the snapshot/memento pattern

I understand that an aggregate root usually replays all events to put itself in the right state. This can become inefficient, hence people suggested the memento pattern to create a snapshot of the aggregate root. My understanding is that the domain…
cs0815
  • 16,751
  • 45
  • 136
  • 299
2
votes
1 answer

Java - Memento pattern and Undo

I am implementing an undo/redo function which requires me to use memento pattern. The flow of the partial program : "...the program then store the previous Vector using Memento Pattern, then the newly created object will be added to the Vector.…
Junior Programmer
  • 310
  • 1
  • 6
  • 20
1
vote
1 answer

What is the difference between the Momento and Prototype Design Pattern?

Observed differences between the Momento and Prototype Design Pattern (from the GOF): The Momento design pattern uses class x to create a snapshot of the internal state of class y. The Prototype design pattern uses class y to create a snapshot…
1
vote
0 answers

Using memento pattern to restore a Vector in java

I am trying to save the vector and use undo method to restore the vector by using a memento pattern, but it is not working. Caretaker.java: import java.util.*; public class Caretaker { private Vector undoList= new Vector(); …
AngusC
  • 11
  • 2
1
vote
1 answer

Can I use Memento Design Pattern for JFreeChart?

Is it possible to use the memento pattern for undo operation in JFreeChart? If it's possible please give me some examples of it.
1
vote
2 answers

Memento in java. Mutable state

I am trying to understand the Memento Pattern. For that purpose i am trying to implement the undo function. The problem is that when ever i save the old state of the originator in the queue and run a different function the save state changes to the…
DerMann
  • 223
  • 1
  • 2
  • 13