What is the right MVC diagram for a web application?

Solution 1:

They all are.

MVC is a vague pattern.

My view on MVC is that :

Controller

Object has a collection of models and has methods for viewing and editing the models. It talks to Models and returns instances of Views with models applied on them.

View

Has the definition of a model attached to it and is just a set of functionality to display a specific model.

Model

Encapsulates data. Has methods for returning state and changing state.

//Controller
import Views

class Controller
  private Models

//View
import Model

class View

//Model
class Model

A Model doesn't need to know anything about the View / Controller. A View needs to know the definition of a Model. A controller needs to own Models and needs to know definitions of Views.

You can couple them more tightly, that is optional.

Solution 2:

MVC, strictly speaking, is kind of an outdated pattern. Coarse-grained speaking, it introduces dependencies between View and Model, since Model updates View status directly (http://www.mimuw.edu.pl/~sl/teaching/00_01/Delfin_EC/Overviews/MVC.htm), as showed in diagram 4, where you see direct interaction between Model and View, according to MVC original, historical formulation, and this is not desirable. In fact, today we have modified versions of MVC, and sometimes we describe MVP and call it MVC. The acronym "MVC" has been used with so much freedom that anything where you have three elements called Model, View and Controller is basically MVC, despite implementation details and Responsibility definitions. The difference is really subtle between MVC and MVP, when you describe them, and resides in the definition of View and Presenter (Controller) responsibilities. Martin Fowler, in fact, gave MVP (and MVC) his goodbye some years ago (http://www.martinfowler.com/eaaDev/ModelViewPresenter.html), and we can find, from his part, the definition of a "new" pattern called Presentation Model (see http://martinfowler.com/eaaDev/PresentationModel.html), or PM. Microsoft has defined for its WPF and Silverlight technologies another pattern, called Model-View-View-Presenter, or MVVM (see http://msdn.microsoft.com/en-us/magazine/dd419663.aspx), which has Presentation Model as his inspiration. I think you can take a look at all these guys and figure how much alike (and different) they are. In my humble opinion, the basic idea is that Presentation data and behavior stays in Presenter, Model doesn't know View (so diagram 4 is off, even also being MVC), and you should be able to change View (or support different View implementations) in a painless way, decoupled from both Presenter and Model. Presentation Model can provide this and is effective and thorough to implement using current technologies.