wood burning stoves 2.0*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Client GUI and MVC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Client GUI and MVC" Watch "Client GUI and MVC" New topic
Author

Client GUI and MVC

Miguel Roque
Ranch Hand

Joined: Oct 24, 2002
Posts: 126
Hello people.
Please review my client side design and the MVC implementation.
To start, I have a FBNClient class that asks for the location of the database or the URL and port of the server. This class then creates a new class called FBNMainWindow. The main window creates the model, three views and one controller.
The model extends DatabaseFacade and implements the search method and the reserve seat method and registers the views to it (for now only table view is registered). I have the search view with 2 combo boxes and a search button, the reserve seats view with a text field and a reserve button and the table view that implements my FBNViewInterface that has only one method in it that is updateView(Object[][] data).
The controller extends ActionListener and ListSelectionListener and all the actions are registered to it. The controller controlls the selection of a row in the table so that it can enable or disable the reserve button. When the search button is pressed, the controller calls the search method in the model. The reservation action when executed, creates a new class that shows a dialog that informs the user to wait. This class also creates a thread that calls the reserve seats method on the model.
Please comment.
Thanks,
Miguel
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937
Miguel,
Good work, you are a rising star in this forum.
I have a few comments, though:

To start, I have a FBNClient class that asks for the location of the database or the URL and port of the server.

So, you are not specifying the database name for networked mode? That is, the only database that you can connect to in networked mode is db.db?

The main window creates the model, three views and one controller.

The View should not create the Model. Create your model, controller, and views in a separate class, something like StartClient.java. For example:


The model extends DatabaseFacade

So, your Model IS DatabaseFacade? Are you sure?. Perhaps, the relationship "Model USES DatabaseFacade" is more intuitive?

and the table view that implements my FBNViewInterface that has only one method in it that is updateView(Object[][] data).

I guess I managed to persuade at least one person in the superiority of Observer-Observable.
Eugene.
[ February 20, 2003: Message edited by: Eugene Kononov ]
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

The controller extends ActionListener and ListSelectionListener and all the actions are registered to it.

why does it need to extend these two classes, and how do you overcome the Java rule that you can't extend two classes. Or do you mean they implement them. I think you will find that you will then have to have many If statements or a big Case statement for every Object on the View that you need to listen too. How about using anonymous inner classes instead?
I also don't see an Observer-Observable case here.
Or do you mean here.
and registers the views to it (for now only table view is registered).

So the model registers with the view, or the model registers the view to itself? I am confused here.
And what does this part do?
updateView(Object[][] data).
I can guess it is to update the JTable, so that says to me that you are not using the DefaultTableModel and customizing it to the assignement. Am I correct in this assumption?
Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Miguel Roque
Ranch Hand

Joined: Oct 24, 2002
Posts: 126
Hello Eugene and Mark

So, you are not specifying the database name for networked mode? That is, the only database that you can connect to in networked mode is db.db?

In network mode, it's hardcoded that it must use db.db. Why should I ask for the name of the database for a network connection to the user?

The View should not create the Model. Create your model, controller, and views in a separate class, something like StartClient.java.

This part I don't understand! The main window that I mention it's a class that creates the main JFrame and add the three views to it! The way I see it, this class it's the StartClient that you mention.

So, your Model IS DatabaseFacade? Are you sure?. Perhaps, the relationship "Model USES DatabaseFacade" is more intuitive?

You are right. I've changed that so now the model USES DatabaseFacade.

why does it need to extend these two classes, and how do you overcome the Java rule that you can't extend two classes.

I've reinvented the weel . I've implemented these two interfaces. That's what happens when we are writing in a hurry .
How about using anonymous inner classes instead?

This one I don't understand . Do you mean to have anonymous inner classes in the main window that creates the 3 views and these anonymous inner classes will call methods on the controller? Can you clarify this?

I also don't see an Observer-Observable case here.

And I haven't used it. I have a FBNViewInterface as follows:

This interface is implemented by the FBNTableView. When I create the model, I pass this FBNViewInterface to it so that it can call this method on the table view.

I can guess it is to update the JTable, so that says to me that you are not using the DefaultTableModel and customizing it to the assignement. Am I correct in this assumption?

My JTable is created using a FBNTableModel that extends AbstractTableModel. Also the JTable has a custoum header renderer so that the table header can be presented in 2 rows.
Let the comments continue .
Miguel
Miguel Roque
Ranch Hand

Joined: Oct 24, 2002
Posts: 126
Hello again.

This one I don't understand . Do you mean to have anonymous inner classes in the main window that creates the 3 views and these anonymous inner classes will call methods on the controller? Can you clarify this?

No need to clarify this one. What you mean are methods in the view like and then in the controller I will have something in his constructor like

Correct Mark?
Miguel
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937

In network mode, it's hardcoded that it must use db.db. Why should I ask for the name of the database for a network connection to the user?

Although not in the requirements explicitely, it is implied that your server should be designed for reuse. Since it is almost obvious that in addition to db.db some other tables will be added in the future, your server could be designed so that it doesn't require any change when it happens. And I mean, not a single line of code need to be changed. It's easier to implement than you may think, so I suggest you consider it.

This part I don't understand! The main window that I mention it's a class that creates the main JFrame and add the three views to it!

That means that your window (View) knows about other views. What I suggest is that you use a completely separate class that acts as a driver for your application, something like this:


And I haven't used it [Observer-Observable, -- my insert]. I have a FBNViewInterface as follows:
public interface FBNViewInterface {public void refreshView(Object[][] data);}
<hr></blockquote>

Well, you may not realize it, but it is your implementation of Observer-Observable. The model calls the refreshView() method on the registered views, right?

My JTable is created using a FBNTableModel that extends AbstractTableModel.

What makes it a bit confusing is that in addition to JTable (which is a view for the table), you also have another table view. If you rename that other view, everything will fall in place.
Eugene.
[ February 20, 2003: Message edited by: Eugene Kononov ]
Miguel Roque
Ranch Hand

Joined: Oct 24, 2002
Posts: 126
Hello.
Although not in the requirements explicitely, it is implied that your server should be designed for reuse. Since it is almost obvious that in addition to db.db some other tables will be added in the future, your server could be designed so that it doesn't require any change when it happens. And I mean, not a single line of code need to be changed. It's easier to implement than you may think, so I suggest you consider it.

It has already been done! In this link i discuss my server implementation and as you can read the server can open a unlimited number of databases.

That means that your window (View) knows about other views. What I suggest is that you use a completely separate class that acts as a driver for your application, something like this

I will look into this.
Well, you may not realize it, but it is your implementation of Observer-Observable. The model calls the refreshView() method on the registered views, right?

Yes, you are right. It's my own implementation of Observer-Observable.
What makes it a bit confusing is that in addition to JTable (which is a view for the table), you also have another table view. If you rename that other view, everything will fall in place.

Rename the other view? Please clarify.
Thanks,
Miguel
Miguel Roque
Ranch Hand

Joined: Oct 24, 2002
Posts: 126
Hello.

FlightsModel flightsModel = new FlightsModel(tableDataModel);

With this, do you mean that we pass the table model to the database model? If yes, we don't need to implement the FBNViewInterface interface and when data changes, we fire the tableDataChanged.
Thangs,
Miguel
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937

With this, do you mean that we pass the table model to the database model?

Actually, this is how I did it, but since then I realized that there are better alternatives. So, I do not recommend passing table model to application model, -- the table model should only be known to the View where the table is contained.

It has already been done! In this link i discuss my server implementation and as you can read the server can open a unlimited number of databases.

So, if your server can open multiple databases, how does a client requests a specific one without specifying its name in the networked mode?

Eugene.
[ February 21, 2003: Message edited by: Eugene Kononov ]
Miguel Roque
Ranch Hand

Joined: Oct 24, 2002
Posts: 126
Hello Eugene.
So, if your server can open multiple databases, how does a client requests a specific one without specifying its name in the networked mode?

I don't see why the client must supply a database name for a network connection!
The server can be considered a final server and that's why it can open a unlimited number of database tables, but the client application it's not final or then we will have to add the clients table, booked flights table and others.
Now imagine, if someone extends the application and add's views to work with customers table and booked seats table, that someone must create a new model and views to manipulate the clients database and booked seats table. By that time should the program asks to the final user the name of the flights, clients and booked seats table? Now imagine a application that works with 10 different tables?
Miguel
[ February 21, 2003: Message edited by: Miguel Roque ]
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Originally posted by Miguel Roque:
Hello again.
and then in the controller I will have something in his constructor like

Correct Mark?
Miguel

Yes exactly like that.
Mark
 
wood burning stoves
 
subject: Client GUI and MVC
 
Similar Threads
general design review
Design review
Design Review part III
MVC pattern again - with one class per view
Review please.