MVC question: direct modell <-> view communicat

2019-02-21 02:10发布

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

2条回答
爷、活的狠高调
2楼-- · 2019-02-21 02:30

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.
查看更多
疯言疯语
3楼-- · 2019-02-21 02:37

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

enter image description here

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).

enter image description here

查看更多
登录 后发表回答