Click to See Complete Forum and Search --> : Is memento a good design decision here?
Rigel
July 29th, 2005, 11:21 AM
This might be a really stupid question. :blush: I'm just beginning to learn more about design patterns.
Ok, let's say that I want to detect whether or not a user has made a change anywhere in the dialog box. If the user has made a change anywhere, then I must set the configuration. I cannot set the configuration in the user has *not* made any changes.
This dialog box contains *many* different text fields, combo boxes, radio buttons. It seems to me that using memento would be a right approach for this problem? Or is there a better approach or alternative?
cvogt61457
July 29th, 2005, 11:34 AM
What is momento?
I would use a set of variables to capture the settings in the dialog on entry.
When the user exits, compare the saved values against the current. If
different, then the user changed something.
Rigel
July 29th, 2005, 11:52 AM
Ok... stupid question... :blush:
Just want to make sure I'm understanding the pattern correctly.
Memento - "Without violating encapsulation, capture and externalize an object's internal state so that the object can be restored to this state later"
Graham
July 29th, 2005, 01:08 PM
Can you give some more details about how you intend to use this pattern in this instance? Do you intend to use a memento to compare the field values to look for differences, or do you have some other purpose in mind?
KevinHall
July 29th, 2005, 02:35 PM
Memento - "Without violating encapsulation, capture and externalize an object's internal state so that the object can be restored to this state later"
Do you really need to externalize the internal state? Is the method you are working on really external to dialog?
If the method is a member function of the dialog, then you don't need to externalize the data and thus memento would be a bad pattern.
If the method is external to the dialog, then memento seems like it would fit, but then I would wonder if you are really saving yourself work by making this method a non-member.
Rigel
July 29th, 2005, 02:42 PM
Can you give some more details about how you intend to use this pattern in this instance? Do you intend to use a memento to compare the field values to look for differences, or do you have some other purpose in mind?
Yes it would be used only to make a comparison and to look for differences. The class would consist of a function SetState and maybe have a function CompareState or something of that nature.
Is this pattern an applicable identification of this situation? It seems that Memento is used for "rolling back/undo" but not for making comparisons such as this. But in both situations you are saving the internal state of an object.
Graham
July 29th, 2005, 05:27 PM
I think it's novel use of Memento, and would probably work. It may be overkill, though - is there a reason why you can't just keep a "dirty" flag in the dialog class? You don't say what OS you're using, but Windows controls will notify you if they change, and you could use that notification to record that the dialog has changed.
Andreas Masur
July 30th, 2005, 05:05 AM
What is momento?
Memento (http://home.earthlink.net/~huston2/dp/memento.html)
Rigel
August 1st, 2005, 09:24 AM
I think it's novel use of Memento, and would probably work. It may be overkill, though - is there a reason why you can't just keep a "dirty" flag in the dialog class? You don't say what OS you're using, but Windows controls will notify you if they change, and you could use that notification to record that the dialog has changed.
Thanks Graham.
You are right, memento is overkill.
I am using Windows ... I never realized that windows controls will notify me if they change. I'll look into this in more detail.
Thanks! :)
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.