Results 1 to 6 of 6
Thread: mvc-model view controller
- 01-07-2010, 06:38 AM #1
Member
- Join Date
- Nov 2009
- Posts
- 54
- Rep Power
- 0
mvc-model view controller
Hey,
I'm trying to understand the model-view-controller design patter, but I have a problem: Normally the model holds the data with get( ) and set( ) methods on that data. But what to do if several views, and thus several controllers, must access the model? Normally seen, 1 controller per view seems the best to me.
Hannes
- 01-07-2010, 06:43 AM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Not sure what the question is here.
One model many views is the reason why the pattern exists. Different people can look at the same data in different ways using different media.
- 01-07-2010, 07:05 AM #3
Member
- Join Date
- Nov 2009
- Posts
- 54
- Rep Power
- 0
yes, but in this case each controller shouldn't own the object who is accessed by many controllers and then theren is no explicit model, or am i wrong?
- 01-07-2010, 07:11 AM #4
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
I don't understand the meaning of your statement.
Basically it's better (IMO) to keep the view away from the model. Thus the view requests it's data through the controller. You can further split the controller into two. 1.)A part that manipulate the model data. This part can be reused by many views.
2.)A part that retrieves data for the view. This part may need to be reimplemented/customized for different views.
- 01-07-2010, 06:18 PM #5
Member
- Join Date
- Nov 2009
- Posts
- 54
- Rep Power
- 0
I'm going to ask it a different way: Does each component have its own controller and model, or does the whole application have 1 controller, 1 view and 1 model?
- 01-08-2010, 05:52 AM #6
Senior Member
- Join Date
- Aug 2009
- Location
- Pittsburgh, PA
- Posts
- 282
- Rep Power
- 4
There is one model.
There may be many views.
When the data in the model changes, it calls its listeners.
Each view listens to the model and updates the view when a change occurs.
If all the views are instances of a single class, they all behave the same.
Only one controller is needed. It updates the model based on actions to the views.
The controller listens to events from the view to decide how to change the model.
If there are different kinds of views--say different view classes--
then there will be one controller per kind of view.
Because the events coming from the view will likely difffer
in source and meaning.
Similar Threads
-
JTable view/model sync problem
By edcincy in forum AWT / SwingReplies: 0Last Post: 09-12-2008, 06:25 PM -
Model View Controller with Java
By chopram in forum New To JavaReplies: 8Last Post: 06-07-2008, 09:18 PM -
Model-View-Controller
By Abnoba12 in forum Advanced JavaReplies: 1Last Post: 05-15-2008, 12:32 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks