0

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?

2 Answers 2

1

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
  • But how will the View update itself? Does it poll the model constantly to see if there are updates? This doesn't seem right, there may be delays in updating, there may be many 'views' attached to a model. Like CPU architecture it seems to me it would be better for the View to register an interrupt, triggered by the model. But how best to implement this?
    – jimscafe
    Apr 20, 2016 at 0:58
0

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
  • 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. Mar 31, 2013 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, 2013 at 12:57
  • Controller == Input processing; View == Output formatting; Model == Domain Logic. Simple as that.
    – tdammers
    Mar 31, 2013 at 13:36

Your Answer

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

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