File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Design Question for MVC 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 "Design Question for MVC" Watch "Design Question for MVC" New topic
Author

Design Question for MVC

Daniel Breitner
Ranch Hand

Joined: Nov 13, 2008
Posts: 70
Hello everybody,

I just wanted to know your opinion about this MVC Design :

The Controller gets a reference to the Model which is retrieved from the Server before GUI - startup.
It also gets a Reference to the View and starts the GUI after initialization.

The View gets a Reference to the Controller to call methods like "book room" or "search rooms", and a reference to the model to get the initial data.
Upon startup it registers an Observer at the Model to be informed of changes.

The Controller takes the requests from the model, calls the Server and performs changes on the model.
The only reason (as I see it) to call the View is to show messages (error ...).

What do you think of that ?

bye,

daniel


Visit me at http://liferay-blogging.blogspot.com
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2492
    
    8

Hi Daniel,

You planning to use the observer design pattern - whenever the model changes the view also get updated automatically?

In general your approach looks fine. Yet the GUI really is the JTable with each record a Room (a model per se). So your controller needs to call "book" and "search" functions interacting with the table model and the data file/server.

For error notifications, it depends on how many exceptions you are catching in the client code. The server side surely has many to cater so classifying or grouping exceptions into 1 or 2 is a good idea. I used 1 server exception (remote exception) and 1 database exception (record not found type exceptions).


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5 OCPBCD5
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5389
    
  13

Hi Daniel,

I have some database exceptions, which are caught in my business service and then an appropriate business exception is thrown instead (so a RecordNotFoundException is caught and a NoRoomFoundException is thrown for example). And I have a lot of business exceptions, because not everything is a RemoteException or a NoRoomFoundException (for example RoomAlreadyBookedException).
In my GuiController all these business exceptions are caught and a GuiControllerException is thrown (with an appropriate message for the user) and so in my application I only have to catch this GuiControllerException and show its message.

Kind regards,
Roel


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Daniel Breitner
Ranch Hand

Joined: Nov 13, 2008
Posts: 70
Ok, throwing exceptions and showing them in the GUI is also a good idea. In my approach it would lead to the Controller not knowing anything about the GUI ...
I have to think about it.

I changed my approach to the following:

GUI gets the Model and it into a JTableModel. this JTableModel class serves as a Wrapper or Adapter for the Model and filters out columns like "deleted" and enhances data for better readability.

The GUI calls the Controller to book or search and the Controller contains the business code querying the Server.
The Controller updates the Model and the Model offers an updateModelListener Interface for the GUI which therefore updates itself.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Design Question for MVC