Ideally, MVC should know the model?

My question is about the ideal or original interpretation of MVC http://heim.ifi.uio.no/~trygver/themes/mvc/mvc-index.html

As the goal of MVC is to reduce dependencies, should View know the model? Then what would prevent it from becoming fat and calling directly the methods of the model without a controller request?

Update: as I read below, I will take a specific example:

Let's say you create a complex calculator (and not just a simple one, let them say the pricer option for the stock market). This requires only input, such as stock price, interest rate, volatility. So, why should I create a link to the entire model that contains the methods from the view, since I only need these input variables?

Why won't the controller just be notified when something changes in the view, and then only call the method in the view with input?

For example, here I see that the view has a link to the entire model:

http://leepoint.net/notes-java/GUI/structure/40mvc.html

private CalcModel m_model; 
+7
language-agnostic design-patterns model-view-controller
source share
5 answers

A view does not need to know about a business model, right down to the controller. However, opinion should be aware of the data model. How else should he introduce him?

See also:

  • Creating Web Application Templates
+17
source share

Then what would prevent it from becoming fat and calling directly Methods of the model without a controller request? without a controller request?

I found this a bit humorous. Views don't have their own minds, but programmers do it. These are those who make bad decisions and give permission to view in order to do what he does.

The view should have enough model information to display. If your programmers cannot control themselves, one answer may be to make Model objects immutable.

Another may be the use of AOP. Write an aspect that prevents service level calls that are not coming from other services or from controllers.

There is another point of view: AJAX is all about views that take things into their own hands and make calls to services without any permissions, do asynchronously and improve responsiveness for a better user experience. This is a good thing.

Don't talk too much on architectural cleanliness. MVC is a great template and is very useful where it is applied. Know the rules; Know when it’s necessary to break the rules. Do not be so dogmatic - in programming or in life.

+7
source share

Yes, in MVC, the view knows about the model. In fact, the purpose of the presentation is to display the model so that it knows about the model. Models should be pretty simple and should not be pretty much containers of state (that is, properties that are strings, int, etc.) - there should be no methods on it.

The controller knows both the view and the model. The controller's task is to obtain the appropriate model and pass it to the appropriate form.

The model should be blissfuly not aware of either the controller or the presentation.

This is a typical separation of problems in MVC (SoC), where each component has a well-defined β€œwork”.

+4
source share

In MVC, the point is not that you should not communicate between MVCs. The point is to separate the model from the view (and the controller) so that you can easily change / replace components.

http://en.wikipedia.org/wiki/Model%E2%80%93View%E2%80%93Controller

+1
source share

The purpose of the presentation is to provide data derived from the model. So the answer should not. On the other hand, the model should not care how these data are presented.

For example, business logic could be:

   view-> report-> annual_revenue =
     this-> first_quarter_rev +
     this-> second_quarter_rev +
     this-> third_quarter_rev +
     this-> fourth_quarter_rev;

While presentation logic:

   if (! this-> report-> annual_revenue) {
     print ('No information')
   }
   else {
     print (format ('# ###', this-> report-> annual_revenue) + '$');
   }
0
source share

All Articles