Reputation: 451
I have searched and searched but got no answers: How should the MVC pattern work?
So long I got two examples out of many similar ones: one of them suggests that the view
should be updated by the controller
, but the model
is directly updated by the view
, and another one suggests that the model
should be updated by the controller
, but the view
should be updated by the model
.
I have learned that the view
should display content from the model
fetched by the controller
, and the model
content would be altered by the view
and updated by the controller
.
Upvotes: 2
Views: 297
Reputation: 451
It's been a year, and I got no answers. Maybe because the question is kinda opinion-based, or maybe because it didn't get much attention.
But ever since then I searched and studied more and more about best practices and design patterns, and now I feel confident enough to answer my own question.
Q: So, how should the MVC pattern work?
A: It should work the way you design it.
The MVC pattern defines three vital types of components: the Model
, the View
and the Controller
:
Now, how's the usual data flow of a MVC application?
That was only the reading flow, the writing flow is similar but a bit different:
Now, when I first asked this question, I was with a Java-heavy mindset, so I wanted to know how would I go about implementing this in Java:
insert
, select
, list
, update
and delete
).So, my final answer is: There's a lot of correct ways of implementing the MVC pattern. But there's a series of guidelines you should follow if you want your implementation to be correct.
Upvotes: 3