aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes good old(!) 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 "good old(!) MVC" Watch "good old(!) MVC" New topic
Author

good old(!) MVC

aadhi agathi
Ranch Hand

Joined: Apr 29, 2002
Posts: 263
MVC
this is my setup (tx to is this MVC topic)
Controller knows Model (there is only1 model)
Model knows data repository (DataInterface) and knows registered view.
View knows controller and creates specific class controller(inner class) and
all get registered with model thr' specific class controller it has created.

now,
1) do the specific views need to get derived from the same view,
having getValue and setValue()??? if so what is the going to
achieve as my specific view knows the specific inner class
controller . but my intitution says that there needs to be
a general view.

2)my model has a getTableModel. does it nned to have different flavors for
getReservationModel, cancell and searchModel , because i have only
1 model and i am having a hidden field with status "B","C" to
know whether it is booked of cancel.
(OR) i have only one getTableModel and the view should ensure to get
the correct version of booked or cancel view


waiting for some one to help me and save MVC too .

regards,
Aadhi
[ January 22, 2003: Message edited by: aadhi agathi ]
[ January 23, 2003: Message edited by: aadhi agathi ]

Aadhi
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17257
    
    6

Why does the GUI know about the controller? The GUI should not know anything about the controller.
Mark


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

Joined: Jun 20, 2001
Posts: 46
controller as inner clas of the gui? doesn�t seem a good solution to me, very high coupling between them.
also: if controller knows about model, that's because you are implementing business logic in the controller, and if so, it doesn�t seem a simply controller class to me.
the responsabilities of a gui controller are to me handling events and implementing relations between gui components (enabling components under certain situations, etc), with no business logic at all.
the GRASP principles " high cohesion, low coupling " seems to me basics when designing classes.
hey, it's just my opinion.


Regards<br />J.
aadhi agathi
Ranch Hand

Joined: Apr 29, 2002
Posts: 263
Originally posted by Mark Spritzler:
Why does the GUI know about the controller? The GUI should not know anything about the controller.
Mark

hi Mark,
the controller takes the responsibility of binding the view with the model. so when there is an action performed in the view like "click the book button", it will send itself to the inner class of the controller, which is a specific controller for the book action. it will ask the getValue of the view and pass it to the Model's set value. the View knows the controller just to get its event dispatched. if the view shoudln't know ANYTHING about the controller how will the view events be dispatched.
maybe i will give the sample code
<CODE>
interface FlightView has getValue and setValue
ReservationView implements FlightView{
//pass itself to the specific controller
//which it has created
ReservatioView(FlightContoller fc){
fc.new ReservationController(this);
}
update(){
//refresh itself
}
}
FlightController
inner class ReservationController listener{
//get view ref in constructor
//so that it can be
// delegatedmodel
ReservationController(FLightView fv){
}
actionEvent(){
//get views value and pass
//on to the controller
}
}
Model
</CODE>
could you please comment on this.
regards,
-Aadhi
aadhi agathi
Ranch Hand

Joined: Apr 29, 2002
Posts: 263
Originally posted by Jaun Katabasis:
controller as inner clas of the gui? doesn�t seem a good solution to me, very high coupling between them.

please check my previous post and let me know if it is still high coupling.and ofcourse, thanks much for the suggestion
aadhi agathi
Ranch Hand

Joined: Apr 29, 2002
Posts: 263
any thoughts from anyone??
regards,
Aadhi
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi
"[..] if the view shoudln't know ANYTHING about the controller how will the view events be dispatched.[..]"
In my design I have MVC too. Suppose we have one model, one controller, one view.
If you create everything in this way you don�t have problems with event dispatching.

When you will create the controller in the constructor you can call one method from the view:

and as the parameter put the contoller itself or another helpful object. On the view side this method can register the parameter as the listener on specific gui component.
What you think?
Regards, Kinga
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17257
    
    6

Here's my solution. In the GUI, I only have code for displaying the GUI, and then there are Public methods that accept Listeners. One method for each one that a GUI Object needs to notify those listeners.
In my controller, and I take the word Controller emaning it controls everything. Hence I have a reference to the GUI and the Model in the controller, and it controls the messages being sent between the GUI, the Model and all actions that occur in the GUI.
So what this means is that the Controller will call one of these "Hook" methods in the GUI to register itself as a listener to a particular event.
Here is an example of a "Hook" method in the GUI

The controller has a reference to the GUI, lets say a variable called myGUI. I then call a method on the GUI like thus

searchFlight is a method I have in the controller that does the action that I want performed when a user clicks the Search button on the GUI.
I hope that makes sense. And while there might be some other solutions that can also work, and work well (Eugene's ).
Mark
aadhi agathi
Ranch Hand

Joined: Apr 29, 2002
Posts: 263

Mark[/qb]<hr></blockquote>
1) my basic concern is , where will the above code be pasted. somewhere in the controller i will say , loop thr' the views and say if it is a searchView then (SearchView) view.searchAction.
do u feel this will be good or the view says,
register with a particular controller inner class(actionlistener). !!!
my idea of a controller is that it is only a event dispatcher and it need not hold the references of all the views. if it holds, then it is carrying extra burdern. but the view should know whom it should contact, for event dispatching.

2) i am assuming that the controller will stay intact but the view can change , say for example there are two types of booking , a)normal and b)supersonic . the normal will use a default controller/model. and the supersonic which will user a supersonic controller/supersonic model. then how many hooks should the view provide. ???


i feel there's some thing wrong in exposing a business method part of the GUI, though it hides behind a humble bookingAction

3) but one thing though , my design doesn't make the view as reusable. and even i doubt yours , i by making the view refer to a specific controller, you by exposing the extra interface.

i am not very sure about effect of exposing an extra interface in the GUI

could you please explain further on the above.
please let me know your views. i really appreciate your help !!
[ January 26, 2003: Message edited by: aadhi agathi ]
[ January 26, 2003: Message edited by: aadhi agathi ]
aadhi agathi
Ranch Hand

Joined: Apr 29, 2002
Posts: 263
any thoughts friends???
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17257
    
    6

but the view should know whom it should contact, for event dispatching.

NO, it should not know who to contact at all. The view just has to look pretty.
It should be in the Controller, it should have a reference to your View/GUI. The word controller means to control, it is the workhorse and the one class that should control everything. In order for it to control it has to know about the other parts.
Mark
aadhi agathi
Ranch Hand

Joined: Apr 29, 2002
Posts: 263
Originally posted by Mark Spritzler:

NO, it should not know who to contact at all. The view just has to look pretty.
Mark

i accept 100%.
1)but is it more bad than exposing an extra interface in the view. .
i will take your advice of using the hooks. my main concern is whenever a new View is added i have to change the controller to incorporate the View. is it reasonable. :roll:
2)where to draw the line for the hooks. for example, i want to show a WAITING_CURSOR whenever a booking request is made. in other words the Controller should call the setCursor on the view. what i am interested to know, essentially is, does the Controller know the view as an JApplet or SearchView ???(something else). here Controller says tries to "recognize" each view and expects the view to look in a particular way thr' hook methods until the time it processes the business operation.

the Controller trying to "recognizing" (typecaset) and controlling the viewability of the View when it is processing the business method

it boils down to which should be the first conideration for reusablity the View or the Controller. so you are winning hands down
though i am still confused about the incorporation of a new View in the controller.
Thanks for being sooooooooo considerate.
[ January 27, 2003: Message edited by: aadhi agathi ]
[ January 27, 2003: Message edited by: aadhi agathi ]
aadhi agathi
Ranch Hand

Joined: Apr 29, 2002
Posts: 263
any thougths??
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17257
    
    6

Well I always think of a new view has to do the same functionality, but a different look, or soruce, ie Swing vs JSP and the web. In each view they need to search, book flights, etc. So the controller will keep the same methods, and the views should have the same method names for the Hook methods.
This is where you can further decouple things using middle "Action" classes. I stop at this point. In that while they work, I haven't come across a situation where I really needed that much flexibility.
There is always a trade off, and how far you go is alwyas your decision and should be based on factors that make sense to you.
So in other words, there are no right or wrong answers.
Mark
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: good old(!) MVC