gloeglm wrote:
I don't really get your problem, if you have a new object and "cancel" is clicked, the new object should just be discarded or what do you want to do?
You're perfectly right. Sorry, it was my fault.
I should have mentioned that I'm dealing with a hierarchy of objects.
Let me describe an example scenario:
I have got Parent objects which can own Child objects. For each class, Parent and Child, I have a special editing dialog. Only Parent objects are stored explicitly since they contain their Child objects in a collection which is stored implicitly.
- I create a new Parent and start to edit it in the appropriate dialog.
- I add a new Child object to this Parent and start editing the Child in a sub dialog of the Parent's dialog (There's an "Add Child" action in the Parent's dialog).
- I commit the changes on the Child object by clicking OK in the subdialog. This OK action doesn't save the Child object because it will be saved together with its Parent. So the Child still has no Id.
- I start again editing the same Child object as in step 3 maybe because I think I made a mistake in steps 2+3. There also is an "Edit Child" action in the Parent's dialog.
- But now I cancel the sub dialog. So the Child object should be in the same state as just after step 3.
How can I resume the correct Child object state after step 5?
How do you deal with this kind of problem?
Is there any pattern or best practice?
Or do I really have to preserve the Child's state in a cloned backup copy? (I don't want to write a clone()-method because my real object hiearchy is not that simple as in the scenario above)
Thanks for your hints and opinions,
Stefan