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.

I have a basic issue with the MVC architecture. I am aware that the View usually listens to the Model. But how are user requests propagated to the Model?

Currently I do it like this, when the user clicks e.g. the update Button in the GUI. So the ActionListener calls a method of the View. The View calls a method of the Controller. And the Controller calls a method of the Model.

But I have three concedrns about this.

  • The View must be aware of the Controller.
  • The long call chain seem to be not the right way
  • With the number of user actions, the number of those call chains increase.

What are the best practises here?

share|improve this question
add comment

2 Answers

You're not using MVC correctly. The ActionListener for that button is (part of) the controller in this case.

When a button is clicked, you want to update your model with your new data. The View will automatically update itself.

I suggest you read this:

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

"The View however, knows about the Model. It will poll the Model about the state, to know what to display. That way, the View can display something that is based on what the Model has done. But the View knows nothing about the Controller."

share|improve this answer
add comment

You can use what best suits your needs, but in MVC architecture the Controller send information to the View. The View never use the Model but what the Controller gives him.

share|improve this answer
    
That is not universally true. There are also descriptions of the MVC pattern where the View does access the Model, but only to read the values it needs to display. –  Bart van Ingen Schenau Mar 31 '13 at 12:26
    
I agree with you. Indeed there are many definitions of MVC pattern, but one that is the most common and in my humble opinion the most correct is that to which the Model does all the real business work. The Views provide the look and feel, and the Controller maps one to the other. He asks for best practices. As I said, he can use what best suits his needs, so he can use View to access the Model, but it is not best practice. –  r4M0 Mar 31 '13 at 12:57
    
Controller == Input processing; View == Output formatting; Model == Domain Logic. Simple as that. –  tdammers Mar 31 '13 at 13:36
add comment

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.