Results 1 to 6 of 6

Thread: MVC question

  1. #1
    Dipke is offline Member
    Join Date
    Aug 2010
    Location
    Leuven, Belgium
    Posts
    86
    Rep Power
    0

    Default MVC question

    Hi,

    I have a model that extends Observable and a view that implements Observer.
    With a Controller that checks the mouseclicks.

    But when the user doubleclicks on the view another view has to be updated using the model.
    So that means that the controller needs to extends Observable as well.
    Is this common practice or is there another way.

    thx

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,679
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Dipke View Post
    So that means that the controller needs to extends Observable as well.
    I don't understand your conclusion here: the Controler is notified by the View so it can create another view and registers itself as an Observer for that view again. I don't see where the controller as an Observable comes in ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    Dipke is offline Member
    Join Date
    Aug 2010
    Location
    Leuven, Belgium
    Posts
    86
    Rep Power
    0

    Default

    The model is data from a file and the view is a table displaying the data.
    When the user doubleclicks on a column from the table, the content from the column is displayed as a graph on another view.
    It is the controller that receives the doubleclick so he has to notify the second view that somebody selected a column to display.
    Thats why the controller (in my opinion) has to be an observer for the second view.

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,679
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Dipke View Post
    The model is data from a file and the view is a table displaying the data.
    When the user doubleclicks on a column from the table, the content from the column is displayed as a graph on another view.
    It is the controller that receives the doubleclick so he has to notify the second view that somebody selected a column to display.
    Thats why the controller (in my opinion) has to be an observer for the second view.
    No, think of it this way: V ---> C <--- M where the View and the Model are the Observables and the Controller is an Observer (Listener most of the time). A Controller 'communicates' directly with Views and Models while the Views and Models simply 'signal' their changes to the Controller (through the Observable/Observer pattern or through the registered Listener mechanism). The Controller always is just an Observer.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    Dipke is offline Member
    Join Date
    Aug 2010
    Location
    Leuven, Belgium
    Posts
    86
    Rep Power
    0

    Default

    Hi Jos,

    Ok that answers my question.
    Many thanks.

    Dipke

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,679
    Blog Entries
    7
    Rep Power
    21

    Default

    Just FYI: my V ---> C <--- M model doesn't make the V and M talk to each other; the 'old' MVC model did allow it, but it is often considered 'cleaner' to make all 'communication' go through the middle C component. It makes the Controller more like a 'Mediator' (another design pattern).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. What exactly is this question asking?
    By kmjt in forum New To Java
    Replies: 2
    Last Post: 01-27-2011, 05:01 PM
  2. Question concerning question marks and colons
    By jim01 in forum New To Java
    Replies: 17
    Last Post: 01-14-2011, 01:05 AM
  3. Question mark colon operator question
    By orchid in forum Advanced Java
    Replies: 9
    Last Post: 12-19-2010, 09:49 AM
  4. MVC question
    By Tom_ in forum Advanced Java
    Replies: 1
    Last Post: 08-12-2010, 01:01 PM
  5. help question
    By 99w210 in forum NetBeans
    Replies: 0
    Last Post: 03-08-2010, 06:23 AM

Tags for this Thread

Posting Permissions

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