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?
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.”
1
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.
3