In my URLyBird assignment I have attempted to use the MVC design pattern for the GUI and connection to the DB.
I have designed a JFrame based GUI (which is the View) which displays the hotel room data (using a JTable and associated subclass of AbstractTableModel) and handles button presses by calling methods on a GUIController class (which is obviously the Controller).
I've tried to design my GUIController much like the example in Andrew's SCJD book, and therefore when a user books a room the controller calls the appropriate methods on the implementation of the DBAceess interface (the Data class), i.e. lock, update, unlock, and returns appropriate results or an error message to the View. Therefore this made me believe that the implementation of the DBAccess interface is the Model (as it manipulates the database) - accordingly in standalone mode the Model would be the Data class itself, and in Network mode the implementation of the RMI Remote Interface which communicate with the server would be the Model.
However, when a client wants to search for records the GUIController calls methods on the Data class and returns an instance of a subclassed AbstractTableModel containing all the Room data matching the query, and then the view uses this model to display the search results.
1. My main question is do you think the subclass of the AbstractTableModel is part of the View (as it is displayed in the view), or part of the Model (it is created by the controller and passed to the view, but it does contain "state", i.e. the room record data, and it also has business style methods that, for example, can be called by the JTable to display the background of each column in a different color depending on if the room is bookable)
2. A second question is that when a user books a room, the original room data that was in the JTable must be passed to the GUIController to allow it to check that the room data in the database is the same. Do you think it is acceptable that my view has to extract the record from that JTable AbstractTableModel and pass this an an argument to a GUIController method? (I can't simply pass the record number into the GUIController, because apart from creating an instance of the AbstractTableModel when a search is complete the GUIContoller does not know about (or maintain a reference) to the AbstractTableModel
I'm trying to write up my choices.txt and don't want to say something silly (such as getting the Model in the MVC pattern wrong
). Any wise words would be most appreciated...
[ August 21, 2006: Message edited by: Daniel Bryant ]