aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Questions about MVC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Questions about MVC" Watch "Questions about MVC" New topic
Author

Questions about MVC

Mikael Månsson
Greenhorn

Joined: Sep 20, 2009
Posts: 17
Hi!

I have seen my solution as using MVC, but I'm getting confused of what parts correspond to what.

I have a Window, ClientWindow and ServerWindow that corresponds to "view". They have event listeners, and the ClientWindow has a JTable.

The ClientWindow has a Controller that has a reference to Client, which can be either a remote or a direct client. (The client actually has the same methods, but are invoking on a RemoteDatabase or Database object.)

The model in my case here i would want to see as the Client, since its the object getting all the data.

But I also have JTable containing data...which could be seen as a model for the ClientWindow..so do I have two separate mvcs?

Also for the ServerWindow there is only the Server, and I have skipped a controller for it...and let the ServerWindow invoke directly on it. This is no longer MVC, but a modified one, and it should be ok as long as i justify it in choices.txt, right?
Andy Jung
Ranch Hand

Joined: Feb 07, 2010
Posts: 150
... actually, talking about the mvc design pattern is not at all that what you are thinking of

MVC design pattern in the context of the Sun certification means:

1. Model: represents the application data and the business rules that govern access and modification of this data
(-> has absolutely nothing to do with client features such as JTable etc.)
2. View: renders the content of the model (roughly speaking this includes all your GUI stuff inclusively GUI event listeners)
3. Controller: defines application behavior by interpreting and mapping user gestures into actions performed by the model. (not to confuse with event listeners)

If you conform to the specifics and implications of the MVC architecture (by registering all views to the model and registering controllers to their corresponding views ...) you will achieve a real-time Client-Server application, which implicates that all clients viewing a certain piece of information (like a record) are informed in real-time of changes to that information caused by another client.

When using the term MVC be careful !

For example a very good introduction to this topic is the web based training offered by Sun (Broker Tool application).

SCJP, SCJD
Mikael Månsson
Greenhorn

Joined: Sep 20, 2009
Posts: 17
Thank you Andy, but I'm not sure I'm following completely.

If I see my application as follows then:

The GUI is the view. The controller and client is the controller, and the business interface is the model.
The business model knows nothing about the GUI and i can easily create a web ui using the same model.

This is not following the mvc pattern in what ways?

About my jtable i was thinking that my customized jtablemodel was kind of a model for the table (view) and the event handler for the table model were somehow making its own little mvc pattern within the gui.
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5406
    
  13

Hi Michael,

I have a MainWindow (view) which has a reference to GuiController (obviously the controller). And the controller has a reference to my business service (model). So that's similar to yours (although your controller exists of 2 classes). Added similar explanation to my choices.txt

And like you said the JTable is a little mvc itself.

Kind regards,
Roel


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Mikael Månsson
Greenhorn

Joined: Sep 20, 2009
Posts: 17
Thank you for your reply Roel.

When I think about it, I could actually remove the controller class and purely use my client interface as controller...just that the naming becomes different. I still want to see it as a client though. Client can be of two types, so I'd like to keep it that way.

For the server, I have a mainwindow and a reference to the server, so from the view I start the server directly. This is indeed not pure mvc, correct?
Andy Jung
Ranch Hand

Joined: Feb 07, 2010
Posts: 150
Hi Mikael,

you were right. Sorry, my fault, didn't appreciate your considerations in detail.

Good luck!
Andy
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5406
    
  13

Hi Mikael,

My Controller has a reference to the business service, which can be the local or the network one. The Controller (nor the MainWindow) is aware of which mode (local or network) the application is running in.

My ServerWindow even doesn't have a reference. It just calls a static method from another utility class to register the server object in the rmi registry. So MVC doesn't apply here.

Kind regards,
Roel
 
Consider Paul's rocket mass heater.
 
subject: Questions about MVC