Talk:Memento pattern

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia

comment[edit]


Also, did someone seriously state on here that C# and Java are "identical languages"? I'm not starting a flame war, but I know both well and they are so fundamentally different that to even suggest that is absurd. Learn more about the history and modifications of the language over the years it has been around and the differences become extreme from that of Java (btw, C# is a mix of Java and C++, however no one compares C# to C++) or just visit this site http://rapidapplicationdevelopment.blogspot.com/2013/10/c-isnt-java-learning-via-katas-part-1.html. Having the Java example stay and the C# example go is baseless (i.e. there is no evidence of superiority of either language neither in usage statistics nor in functionality, they are two completely different languages if you actually know them, and the only reason for C# example to go seems to be because the Java code was written first before the C# code was - which is not a strong reason). — Preceding unsigned comment added by 69.2.35.214 (talk) 17:53, 1 December 2014 (UTC)[reply]

Why not just fix the C# example with someone who actually knows C#. That seems like a better solution then just getting rid of it. I helped fix it, but in general it is not functionally equivalent to the Java code. — Preceding unsigned comment added by 69.2.35.214 (talk) 17:43, 1 December 2014 (UTC)[reply]

The Java example is correct, the C# example is flawed. The C# example got to go. My personal opinion is that a stack is often a better solution than memento.


Man, the CareTaker can save more mementos, not only of 1 object, and can save a lot of them. —Preceding unsigned comment added by 24.232.232.20 (talk) 15:16, 15 August 2008 (UTC)[reply]


I would like to request more information on the role of the CareTaker. From the explanation and the samples, it is not clear as to what the purpose of the CareTaker is. Specifically, why would you store the Memento in the CareTaker and not in the code that contains the instance of the Originator. The CareTaker appears to serve no purpose other than to complicate the design. 64.201.213.84 (talk) 01:50, 21 March 2008 (UTC)[reply]


I would use Vector instead of ArrayList in CareTaker, because ArrayList does not take care of sorting. 193.159.228.66 15:06, 11 January 2007 (UTC)[reply]

"The caretaker first asks the originator for a memento object."

This is not in accordance with the given code. There the caretaker is passive. It's the controller (main()) that asks the originator for a memento object and hands it over to the caretaker which only acts as a storage. Md2perpe 20:03, 20 September 2006 (UTC)[reply]

Yes. The code is ridiculous. The "As3Memento" should just be CareTaker. It would be simpler, and would fit the description of the pattern. 82.230.65.68 (talk) 20:33, 29 January 2009 (UTC)[reply]


I think it is ridiculous to post the same (long) code example in two, basically identical languages as C# and Java. One of them should be removed. I don't give preference to any of them, so I'm removing the longer one. --Zigmar 14:33, 31 October 2006 (UTC)[reply]


Now the examples are in ActionScript 3, Java, and Ruby. At least one of these should be removed; ideally, only one would be kept, and in the most commonly used language of the three. Dhasenan (talk) 19:18, 21 May 2009 (UTC)[reply]


Is every trivial thing now a design pattern? Encapsulating the state of an object into a different object is pretty redundant because an object is defined as its own state plus methods (which are the class’ properties).—☠☢☣[d] 00:02, 6 August 2013 (UTC)[reply]

Pseudorandom[edit]

Classic examples of the memento pattern include the seed of a pseudorandom number generator [...] Someone please clarify how the memento pattern is used in this case. Thanks, --Abdull (talk) 21:34, 27 October 2008 (UTC)[reply]


I was wondering the same thing. I couldn't find an explanation on GBooks, and a web search turns up websites that cite the Wikipedia for this example. QVVERTYVS (hm?) 08:08, 20 April 2015 (UTC)[reply]

question on style[edit]

The memento is marked as public static nested inner class. Its enclosing class is package scoped. Do you think that should be improved? Kind regards.

breaks encapsulation[edit]

The C# example contradict the description of the pattern itself: the memento should be an opaque object. The responsibility to restore its state must be in the originator. Setting the state by looking it up in the memento looks like cheating. Atoll (talk) 16:10, 16 October 2017 (UTC)[reply]

Mistake in the UML diagram[edit]

The UML diagram define the method getState() and setState() of the Memento class to be private. But then they are useless. They should be public. Kind Regards. — Preceding unsigned comment added by LC.Wiki.2019 (talkcontribs) 14:03, 28 October 2019 (UTC)[reply]

History of the pattern[edit]

can we get any reference when this pattern was first described ? 2A01:E35:2E0E:EAD0:8C28:12B0:8B25:1308 (talk) 20:41, 16 August 2016 (UTC)[reply]