Hi all !
I have implemented my GUI in a generic way, which means that any kind of view can be easily plugged in the MVC structure.
The controller class defines a number of methods which can recieve parameters, like nrOfSeats or recordNo.
The controller has no knowledge of the view, the view is registered as an observer of the model and
updated when it is notified by the model.
There is, hoewever, a problem with the Swing actions. Because it is not possible to pass parameters
to the actionPerformed method, the Swing actions have a reference "hook" to the view to obtain the
information filled in by the user.
I use an AbstractView class which defines a number of getter methods to read those data. The AbstractView
class implements the Observer interface and takes care of the updating by calling the abstract method
updateView in its update(Observable o, Object arg) method. This is an example of the Template method
pattern.
The abstract methods getSelectedRecord, getSeats etc. are also defined in the AbstractView method, and implemented in the concrete SwingView subclass.
So far so good. But when we would use another view, for example a text-based view (or Web view), we have
no Swing Action classes, so we van call the Controller methods directly from this view, passing to them
the needed parameters. This would make the use of a "hook" to the view in fact unnecessary !
So, is it a good idea to define an AbstractView which already defines these getter methods ? Using Swing
actions, we have little choice. But the idea of the AbstractView class is that it is the commom
baseclass for all types of views !
Of course, it is still possible to use the getter methods of the View class anyway. In a swing view, these
getter methods read from the JTable and the model, and in a text based view, the underlying properties are
simply set using an assignment statement.
Pretty complicated !!! Who want to share these thoughts with me to come to a good design desicion ???
Regards, Klaas
[ September 07, 2004: Message edited by: Klaas van Gelder ]
[ September 07, 2004: Message edited by: Klaas van Gelder ]