I read a lots of articles about MVC architecture, but I'm still confused.
- Which diagram is correct?
- Does even exist correct implementation of MVC architecture?
- Could I use diferent implementation of MVC architecture?
Diagram 1
Diagram 2
Diagram 3
I read a lots of articles about MVC architecture, but I'm still confused.
Diagram 1
Diagram 2
Diagram 3
My strategy for learning good MVC techniques was to find someone who knew and ask a lot of questions. Asking a bunch of us who do not know your requirements, your intentions, or your ideas does not do a lot of good.
Its my opinion that Diagram 1 would be considered the 'best' diagram, but without knowing your unique situation it would be better to explain your needs to someone else who knows your requirements and MVC architecture.
MVC can be understood by thinking of responsibilities:
The View is not allowed to change the state of the model directly - only through the Controller. The view can still have some direct access to the Model although only for viewing (or by having a copy that isn't the official Model).
The Model should live in its own universe and not have any reference to controllers or to views.
The Controller controls the state and access to the Model.
Definitely not Diagram 3! Diagram 1 is OK. I think the best is basically Diagram 2 with an arrow from Controller to View.
Assuming you are asking in the context of web apps, here is what I think a good MVC flow looks like:
When a web request comes, it is one of 2 types.
Type A - this is a simple request that directly gets mapped to a view, so no controller is involved
Type B - this is request that maps to a controller
For both type A and B a view always reads data from the models directly
If it is a type B request, the controller reads/updates models and when done asks the MVC framework to return a view to the client. The view reads the update models and renders to the client.
This is the approach supported by the Induction MVC framework.
Hope this helps.