Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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 ?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer
    
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 ? –  Amogh Talpallikar Apr 16 '12 at 13:28
    
@AmoghTalpallikar Yes. You should pass values a and b to the model, and it should update the view with the result. –  BЈовић Apr 16 '12 at 13:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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