0

In many User Interface libraries, we have concept of views and subviews. so according to MVC pattern every view should update the model as soon as it changes.

For that view should have a reference of its model. If we have a subview and it does some calculation, then should that model also be passed to the subview or part of that model pertaining to that subview should be passed to that subview.

and Say when we take certain actions, should there be a separate controller for the subview or the actions on the subview should be handled by its parent view's controller ?

1 Answer 1

1

First of all, there is no sub-view in MVC. That means, your sub-view should have it's own model.

The second thing is that a view should not do any kind of calculations*. That is what the model is for.

* The reason not to do calculations in view is because the only way to test a view is to see how it displays what it should display.

2
  • Thanks for the clarification. For the second point of yours I wanted to say view controller but anyways Its the model as you say. So , you mean if I have a view that displays two text-boxes for a and b and one for their sum then I should have three fields in m modle class and sum should be calculated by model only ? Commented Apr 16, 2012 at 13:28
  • @AmoghTalpallikar Yes. You should pass values a and b to the model, and it should update the view with the result. Commented Apr 16, 2012 at 13:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.