aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes GUI architecture question (Passive View) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "GUI architecture question (Passive View)" Watch "GUI architecture question (Passive View)" New topic
Author

GUI architecture question (Passive View)

Sigrid Kajdan
Ranch Hand

Joined: Jan 14, 2007
Posts: 72
Hi all,

after reading about the "Passive View" pattern in "JUnit in Action", I tried to follow it in my GUI part. So, I have the ActionListeners in the controller, not in the view, and whenever the controller needs input data, it asks the view for it explicitly.

However, I'm not really sure that what I implemented actually IS a Passive View... Even though all actions are taken in the controller, there is a connection between the view and the model - the JTable is part of the view, and it has a TableModel. So, I have the following code in the controller:


Does this relationship between table and TableModel already break the pattern?

I must also admit that it's my first experience with GUI programming (making the Swing part quite cumbersome anyway...), and though I've tried reading the articles on "GUI Architecture", "Passive View", "Supervising Controller" etc. on the Martin Fowler website, these things do not really get clear to me

Thanks a lot for any hints,
Sigrid
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2265
    
    3

Howdy, Sigrid!!!

The Controller has to know the GUI and the Model (and by Model, I mean an implementation of the domain model). The model that you set in your JTable is more related to a data model; the data that will be displayed in your JTable. One thing you can do is have a service that retrieves the data that will be displayed in the JTable to build your TableModel. Here's a piece of code I have in the Controller (ActionListener) that performs the search in the GUI:



My window implements an interface called ApplicationWindowManager that has a method called addRoomToDataTable(), and this method deals with the TableModel. So the Controller just asks a service to retrieve the data that will be displayed (according to the search the user performed), gets it and asks the GUI to add it to the TableModel (in fact, the Controller doesn't really know that there is a TableModel). The Controller just has a reference to the interface that the main window implements.

Now, one thing I noticed, is your view implementing some interface that has a method called getTable() that retrieves a JTable? One thing I always try to avoid is to have interfaces that deal with too specilized classes; for instance, in the future, if there's another structure other than JTable, in my case, all that will be necessary is to have another class that implements the ApplicationWindowManager interface and everything else will continue to work normally. This implementation will know how to deal with this other structure and will be able to add records to the view.


Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
Sigrid Kajdan
Ranch Hand

Joined: Jan 14, 2007
Posts: 72
Hi Bob,

thanks a lot for your answer!

Regarding your question about whether my view implements an interface - no, none. In fact in the other parts - network layer, business layer, database layer - I am working with interfaces, but in the GUI part I have a very straightforward implementation of (not taking into account configuration and validation here) just one view, one "BookingTableModel" extending AbstractTableModel and two Controllers (local/networked) with a common superclass.
I suppose this is because in the GUI part, I started out following the Monkhouse book quite closely, having never worked with Swing at all...

Regarding the pattern question again... if I understand you correctly, you would not see a problem in my calling my design a "Passive view", do you?

Thanks again
Sigrid
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2265
    
    3

Howdy, Sigrid!

Regarding the pattern question again... if I understand you correctly, you would not see a problem in my calling my design a "Passive view", do you?


The Passive View pattern talks about a view that is as dumb as possible, and which is controlled entirely by the Controllers. The interesting thing is that the view can be replaced by stubs for testing, and you run little risk for not testing the UI itself. Now, if you have your Controllers sending/retrieving data from the model and handling the state of the UI widgets with this data, and your UI is purely a view, then yes, you can call your UI a Passive View. This is a variation of the MVC pattern, since your Controllers will end up containing more logic in the end.
Sigrid Kajdan
Ranch Hand

Joined: Jan 14, 2007
Posts: 72
Hi Bob,

thanks again... just wanted to make sure I'm not writing something totally incorrect in my choices.txt

ciao
Sigrid
 
 
subject: GUI architecture question (Passive View)