File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes MVC pattern again - with one class per 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 "MVC pattern again - with one class per view" Watch "MVC pattern again - with one class per view" New topic

MVC pattern again - with one class per view

Venita Glasfurd

Joined: Sep 11, 2002
Posts: 12
I've seen quite a few posts here regarding the MVC pattern, but haven't been able to find the answer to my doubts.
I have one class for each view
-the Search frame
-the Result frame
-the Reserve Flights frame
On click of the Search button, the search frame creates an instance of the Result frame.
on click of Reserve button on the Result frame, an instance of the Reserve frame is created.
Now, when designing the controller,
1. should I have a controller for each View? In this case, where can I instantiate each contoller?
I considered instantiating the controller for my Result frame in the Search frame class and so on, but this goes against the idea that a GUI shouldn't know a controller( even if the controller in this case is not for itself, but for a succeeding frame - is this correct?).
2. Should I have just one controller for all the views?
This means that the one Controller class should have references to all the views(search, result and reserve frames). Again, the reference for each frame can be set into the Controller only from the preceding frame.
Or maybe I should instantiate all my frames along with their respective controller(s), in the main program itself, and show them only at the appropriate moments. Is there any other way of approaching this?
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

In this case I like one controller for all the Frames.

Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
I agree. Here's the link:
subject: MVC pattern again - with one class per view
It's not a secret anymore!