Truly agile Java application developer with Extreme Programming and high quality craftsmanship
Truly agile Java application developer with Extreme Programming and high quality craftsmanship
Originally posted by Jonny Andersson:
I not talk about the micro MVC structure that already is applied to most of the available GUI widgets for Java Swing but instead to the macro structure for the architecture of the overall system.
[...]
But am I wrong? Is it instead the model that should call setters and getters in the view (class)? Like in the micro MVC used for the Swing widgets. I don�t like it
I would have to disagree with your claim that the models of Swing widgets call setters and getters in the view.
Questions about the "macro structure for the architecture" are good to ask, but I'm not sure this is the best forum for it.
Truly agile Java application developer with Extreme Programming and high quality craftsmanship
The JTextField is not the model. Its Document is the model. The JTextField itself is the view (or perhaps a view/controller hybrid). Hence you can do something like to display four fields locked with the same content.Originally posted by Jonny Andersson:
Well, look at a JTextField. You add listener (a document listener) on it and when it gets fired do you get the text content by a call of getText() on the text field (well, or actually on the document for the text field).
First, you don't get the data from the view. You get it from the model. Yes, you can call myTextField.getText() but that's just a convenience wrapper for myTextField.getDocument().getText().But the big question is how to get the data from that view to the application model which know what to do with that data, for example store it to a file or a database, and which contains business logic.
Truly agile Java application developer with Extreme Programming and high quality craftsmanship
Originally posted by Jonny Andersson:
But all these text fields and buttons are usually added to a container, for example a subclass of JPanel (but I would prefer to wrap/encapsulate them instead) which becomes a visual "view" embedded in a frame or another window. And how do you then export the data from that view?
Do you add public getters to the panel subclass to get the data from the models of the widgets? Or do you add the class to which the data should be exported (a class that I call the application model where business logic is applied on the data) as a reference/member of the panel subclass and let the "view" itself export the data by call of setters in the application model?
If you are a true believer in MVC
There would be nothing to "export" because the data you need is just sitting there in a convenient form in your data model.
...
The two options you present here seem to be (A) the application model pulls data from the view, and (B) the view pushes data to the application model.
The application model shouldn't even care about the view(s), right?
Truly agile Java application developer with Extreme Programming and high quality craftsmanship
Originally posted by Jonny Andersson:
Okay, but lets think on a dialog window where insert of a value maybe should cause some other value in that dialog, or maybe in another open window, to be recalculated according to some business logic. I think that business logic should occur in some other class, which I call the application model, outside of the view. The application model should not know from where it got the data, only that it just got some data and now have to calculate on it AND notify all views that is listening on that application model that there have been a change.
From this I gather that we're not completely eye-to-eye on the terminology, because I would think the application model does sort of need to know where it got the data. The application model would register itself as a listener to what I've been calling the "data model." If you disagree then we probably have different ideas about what exactly the application model is.
I would think an MVC implementation of this situation would go like this. When the user inserts the value on the dialog view the view calls a setter in the data model, then the data model fires an even to all listeners. That other dialog is a listener, so it can update that field you're worried about. The application model is also a listener so it knows when to perform its recalculations and whatnot. The application model might end up calling some setters in the data model, which will cause the data model to fire more events so all the views can updates themselves.
Truly agile Java application developer with Extreme Programming and high quality craftsmanship
Originally posted by Jonny Andersson:
This is a different way to structure this that I not have thought about before. It looks reasonable because you separate the business logic from the view as I also want it but it is different in the way that the application model is listening on the same thing as the view does. That sounds a bit strange.
Is the model then something that keeps data, something that represents what is described as the domain model in http://www.jdl.co.uk/briefings/mvc.html?
In that case am I not sure I will agree in that because I think the reason to separate the model in two parts, the application model and the domain model, is to have a domain model that knows NOTHING about its views.
Truly agile Java application developer with Extreme Programming and high quality craftsmanship
Consider Paul's rocket mass heater. |