7
As you all know, the Memento pattern is the pattern that saves different states of objects and then retrieves them.
The intention is not to retrieve the "last" to enter and then remove it? This is a stack, right?
So why do the examples use ArrayList
taking the index element (quantity - 1) and not using Stack
straightforward?
There’s an explanation for this?
Example:
I’m using C#, but I can understand java, so this question is for both.
In C# I’m using List
and to recover I’m using
TextoMemento estadoSalvo = estados.ElementAt(estados.Count -1);
estados.RemoveAt(estados.Count - 1);
Why not Stack
?
What examples? Without seeing what you’re talking about, you don’t know. If you don’t like one example, take one. If you don’t like any, leave them. This example has neither a list nor a stack (and it is canonical): http://www.dofactory.com/net/memento-design-pattern. This also does not http://blogs.microsoft.co.il/gilf/2008/08/01/memento-pattern/. Using a battery for specific need: http://www.codeproject.com/Articles/18025/Generic-Memento-Pattern-for-Undo-Redo-in-C
– Maniero
Check out these examples: http://en.wikipedia.org/wiki/Memento_pattern and https://brizeno.wordpress.com/category/padroes-de-projeto/mediator/ http://imasters.com.br/artigo/16994/java/padrao-de-projetos-com-memento/ I’m running from Brizeno’s website first. also: http://sourcemaking.com/design_patterns/Memento/java/1
– user17245