This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I am still struggling with the GUI implementation. In my first thougts, I considered the TableModel as the "model" in the MVC architecture. But in fact, the TableModel is tightly coupled with a JTable component and therefore part of the Swing-based view. If the application should be extended, for example, having a Web-based interface, we have nothing to do with a JTable and the corresponding TableModel. The view now would be a servlet or JSP page... Therefore, I think that the TableModel class should be considered as part of the View. A separate FlightDataModel class would then be necessary.
The same counts for implementing the Controller actions using the javax.swing.Action class. This class is useful when we want to attach the same functionality to menu items and (toolbar)buttons, but again is completly bounded to the use of a Swing gui.
So my question is, can we assume that only Swing clients are used for the application, or should we make the Controller and Model classes completly swing-independent ? If we do, we can still use the swing Action classes, but these would be part of the View instead of the Controller. The Controller now should contain methods for searcing and booking flights, which recieve some GuiInterface parameter to obtain the search/booking info from the Gui.
View: MainWindow class, Action classes, TableModel class
Controller class: Methods for searching and booking flights, recieving a ViewInterface parameter and filling the Model.
Model class: Contains a private array variable containing the records that may be viewed (= a subset of all records after a search action), a getter method which returns these records, and a method that notifies the Views (called by the controller).
Am I right in my considerations ? Please give my any feedback... :-) Regards, Klaas [ August 01, 2004: Message edited by: Klaas van Gelder ]
"What you don't know, can't help you"
SCJP (81%), SCWCD (81%), SCJD (354/400), SCBCD (85%)
I've implemented the gui on MVC, a beautiful sight to behold. But then I just trashed it, because I realized that I need to do a simple GUI. I now want to minimize the number of classes I need to implement.
My GUI class is GUI (extends JFrame) Controller class is Client (extends Object and knows how to talk via RMI to the server) Model class is DataModel (extends DefaultTableModel)
Controllers are the least reusable element - Actions and mediation, heavily reliant on implementation.
The View is completely agnostic, just dumb components. Totally resusable and extendable depending on design.
The model is 2-fold:
1. Swing related ComboBoxModel & TableModel etc, okay these could be reused for something else, but they are really specific to Swing.
2. Business Tier, which should be more reusable whether thin or thick client is used. But it so simple.
The spec says 'The IT Director does not envisage much reuse of the first java tech system...' Or mine does anyway.
I don't see a problem with implementing MVC over-and-above Swings in built. It can be very simple, there is very little function anyway and most of the notification from model is in built. A simple controller that defines the actions and hooks them into the view with helpers in the view. Initial business setup during controller instantiation and obtaining local or remote connection. Mutable TableModel & ComboBoxModel that the controller updates. And a dumb view.
SCJP 1.4, SCJD
Joined: Jul 02, 2004
Originally posted by Yanxin Zhao: Hi:Anton are you put the Model in suncertify.server? or put Model,view, Controller are all in suncertify.client
I put all MVC classes into the client. I put all business logic into the db and remote packages. I am going to do a very basic gui for the server as well, and that class is in server.
Should be about 15 to 20 classes max, and maybe even as low as 10-15. By the way, their website says assignments with roughly 3,500 lines of code can pass. This sounds like they want a spaceship docking program implemented here. I think one thousand lines will be plenty. I'll post the final stats for my project as soon as I am done.
Joined: May 05, 2004
Hi: Anton Why not put Model into server side? I want to put Model into Server side. when every View starts, registering a instance into Model. When the data got change, the Model will call every View to refresh. but if you do as what you said, how to implement what I said.
Klaas van Gelder
Joined: Jul 08, 2004
OK guys, thanx for all this info ! It does't, however, really answer my questions.... I would like to get some feedback on my considerations in making the Model and Controller independent of the Swing gui, thus making it impossible to use Action classes in the controller. Pleeze see my first mail for the details... I hope for some well-thought reactions, because this item still gives me sleepless nights...
I don't want to get into specifics so let me try and clarify this issue in a general way.
In an MVC2 architecture the dependencies between the components are cyclical. That is, the View depends on the Model for its data; the Controller depends on the View for its actions; and the Model depends on the Controller to update it. Swing combines the View and Controller into an UI Delegate which cements the dependency between View and Controller by making it bi-directional (i.e. they both depend on each other).
The Model is read by the View and updated by the Controller; however, the client and server representations of the Model do not need to be (and arguably should not be) the same. In this instance, on the client side you should use a subclass of AbstractTableModel. On the server side you should use a representation more closely suited to the physical representation of the data (e.g. the file format). You can then add any necessary methods to your TableModel implementation to convert between the two data representations. If you're lucky enough that the server representation exactly matches that required for the TableModel then great, but you should still make the two logically separate.
So my question is, can we assume that only Swing clients are used for the application, or should we make the Controller and Model classes completly swing-independent ? If we do, we can still use the swing Action classes, but these would be part of the View instead of the Controller.
The solution by Eugene (John Smith) on March 11, 2003 7:29 AM might address your questions.