• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Client GUI and MVC

 
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Miguel Roque
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2937
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2937
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic