MVC question: direct modell <-> view communicat

2019-02-21 01:50发布

问题:

can anybody tell me, why communicates the model direct with the view in the MVC pattern, and why not just throught the controller?

http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller

回答1:

Sometimes it is too costly to use Controller for simple View/Model communication.

If your view just shows raw data without any operation (filtration, visualization, modification ...) it is easy to forget about Controller.

But this behavior is so abuse-able sometimes it kills all of the advantages of MVC.

And this where MVP comes in:

MVP (Model-View-Presenter) cuts the connection between model and view and every thing pass through man-in-the-middle (Presenter).



回答2:

The views know of the model and will interact with the model.

  • If a button is clicked an action message might be sent to a model object in order to get something done.
  • If a new value is typed into an entry field an update message might be sent to a model object in order to give it its new value.
  • If a value is needed for a display an enquiry message might be sent to a model object in order to get a value.