|
-
July 29th, 2005, 11:21 AM
#1
Is memento a good design decision here?
This might be a really stupid question. 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?
-
July 29th, 2005, 11:34 AM
#2
Re: Is memento a good design decision here?
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.
-
July 29th, 2005, 11:52 AM
#3
Re: Is memento a good design decision here?
Ok... stupid question...
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"
-
July 29th, 2005, 01:08 PM
#4
Re: Is memento a good design decision here?
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?
Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.
-- Sutter and Alexandrescu, C++ Coding Standards
Programs must be written for people to read, and only incidentally for machines to execute.
-- Harold Abelson and Gerald Jay Sussman
The cheapest, fastest and most reliable components of a computer system are those that aren't there.
-- Gordon Bell
-
July 29th, 2005, 02:35 PM
#5
Re: Is memento a good design decision here?
 Originally Posted by Rigel
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.
Kevin Hall
-
July 29th, 2005, 02:42 PM
#6
Re: Is memento a good design decision here?
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.
-
July 29th, 2005, 05:27 PM
#7
Re: Is memento a good design decision here?
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.
Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.
-- Sutter and Alexandrescu, C++ Coding Standards
Programs must be written for people to read, and only incidentally for machines to execute.
-- Harold Abelson and Gerald Jay Sussman
The cheapest, fastest and most reliable components of a computer system are those that aren't there.
-- Gordon Bell
-
July 30th, 2005, 05:05 AM
#8
Re: Is memento a good design decision here?
 Originally Posted by cvogt61457
What is momento?
-
August 1st, 2005, 09:24 AM
#9
Re: Is memento a good design decision here?
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!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|