Results 1 to 6 of 6
  1. #1
    hannes is offline Member
    Join Date
    Nov 2009
    Posts
    54
    Rep Power
    0

    Default 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

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    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.

  3. #3
    hannes is offline Member
    Join Date
    Nov 2009
    Posts
    54
    Rep Power
    0

    Default

    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?

  4. #4
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    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.

  5. #5
    hannes is offline Member
    Join Date
    Nov 2009
    Posts
    54
    Rep Power
    0

    Default

    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?

  6. #6
    zweibieren is offline Senior Member
    Join Date
    Aug 2009
    Location
    Pittsburgh, PA
    Posts
    284
    Rep Power
    6

    Default

    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

  1. JTable view/model sync problem
    By edcincy in forum AWT / Swing
    Replies: 0
    Last Post: 09-12-2008, 06:25 PM
  2. Model View Controller with Java
    By chopram in forum New To Java
    Replies: 8
    Last Post: 06-07-2008, 09:18 PM
  3. Model-View-Controller
    By Abnoba12 in forum Advanced Java
    Replies: 1
    Last Post: 05-15-2008, 12:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •