Modifying a complicated object with dialog boxes
Hello all,
I'm looking for some advice. Basically I have a GUI that modifies a fairly complicated object. By this I mean that the object can have nested dialog boxes that modify nested elements of the object. ie:
Object A contains
Object B
Object C
If we want to modify Object C, a new dialog box opens.
Object C contains
Object Y
Object Z
If we want to modify Object Z a new dialog box opens for editing etc...
What I'm trying to determine is the best method for editing these objects. I see myself as having 3 options:
1. I can directly modify the reference to Object A, Object C, Object Z etc...however if the user cancels the editing dialog box it may be a pain to rollback changes.
2. I can create an object that stores all changes made and once the user clicks 'ok', I copy over each change to the real object...but that seems like a lot of work and can get cumbersome if I have a lot of different types of objects ;)
3. I simply change the object reference to reference the modified dialog object...but that seems a little dangerous since other objects may still reference the stale object.
What does everyone think the best course of action would be?
Thanks in advance!
Re: Modifying a complicated object with dialog boxes
I will prefer 2 approach , because it seems to be feasible then other 2.
Re: Modifying a complicated object with dialog boxes
To be honest, it doesn't really matter what we think. Which way makes more sense to you? Do that one and go from there.
Or better yet, try doing it in different ways and then use the actual code to determine which is better, however you define that.
Re: Modifying a complicated object with dialog boxes
I have a curiosity question: why are you using dialog boxes instead of a form? It seems a form would solve all of your problems.
If you had to do it with dialog boxes for whatever reason, I would suggest adding to your Objects to make it easier to update data. For instance, lets say you went with #2. I would create a method in your Object A that accepts an Object A and sets the data accordingly. That may be easier to code and more readable than trying to accomplish everything in your main (or where ever). If you went with #1, you could make several methods for each setting variable where it has a 'previous' variable that contains the Object's last value for that variable. Then you could create some methods to set the variables based on the saved previous values. Then you could create a 'rollback' method in Object A that would simply run through and call all of those methods.
#2 is much more elegant and easier than #1, but they are both possible. I would not advise #3. Like you said, problems could occur.
Overall, go with a form if you are not restricted to dialog boxes. If you need help making a form, I can step you through it.
Re: Modifying a complicated object with dialog boxes
As KevinWorkman correctly pointed out that you must do what makes more sense to you, I will point out an alternative:
Quote:
Basically I have a GUI that modifies a fairly complicated object. By this I mean that the object can have nested dialog boxes that modify nested elements of the object
Seems like your data and GUI are tightly intertwined...I'd recommend separating your model/data away from the GUI to make if follow more of a typical MVC (Model/View/Controller) architecture. Embedding both together can grow into a nightmare, and makes making changes (say for instance taking ausiemcgr's advice to make a form) in the long run much harder. Having the two separated makes accomplishing the above a piece of cake.
Re: Modifying a complicated object with dialog boxes
Sorry I don't think I'm familiar with forms...is this a Java object that maybe I'm not familiar with or do you mean using a JFrame? If it's the latter how does it differ from using a dialog box?
Quote:
Seems like your data and GUI are tightly intertwined...I'd recommend separating your model/data away from the GUI to make if follow more of a typical MVC (Model/View/Controller) architecture
I'm keeping all my model data in a controller object. This controller object maintains listeners on the GUI and updates the model appropriately when there are any changes...is this an appropriate way to maintain an MVC architecture?
Thanks for all your responses!
Re: Modifying a complicated object with dialog boxes
Quote:
Sorry I don't think I'm familiar with forms...is this a Java object that maybe I'm not familiar with or do you mean using a JFrame? If it's the latter how does it differ from using a dialog box?
I can't speak for ausiemcgr, but my understanding is they are suggesting a more complex gui than a Dialog, a JFrame containing input of all sorts rather than using successive dialogs that can are cumbersome.
Quote:
is this an appropriate way to maintain an MVC architecture?
The term MVC is extremely broad, and I have seen it 'applied' in all sorts of ways. Its appropriate when the architecture makes the program as flexible and maintainable as possible. Your original question gave me the impression that the model is spread across multiple objects which manage smaller components of the model...and my suggestion was to pull all those out into a single interface/object to give you the flexibility of monitoring/controlling/reverting changes to the model. I will go back and point out KevinWorkman's advice however, whatever makes sense to you. The right way is the way that works.
Re: Modifying a complicated object with dialog boxes
Quote:
Originally Posted by
copeg
I can't speak for ausiemcgr, but my understanding is they are suggesting a more complex gui than a Dialog, a JFrame containing input of all sorts rather than using successive dialogs that can are cumbersome.
Ya, I was referring to a GUI that allow multiple inputs of data in one go rather than one by one.
To give a visual representation of what I mean:
Dialog: http://download.oracle.com/javase/tu...alog2Metal.png
Form: http://download.oracle.com/javase/tu...tInputDemo.png