Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC - is it model to view or controller to view?

I see numerous sites and articles explaining that the view is updated from the model like the example below mvc however i see a few other examples of MVC architecture showing that the view is updated via the controller enter image description here

Is this depending on whether you have the @Model into your views? im just wondering why the different versions of MVC, we were taught that it should be the second image.

like image 501
Matchbox2093 Avatar asked Apr 12 '15 20:04

Matchbox2093


People also ask

What is model view and controller MVC?

-MVC is an architectural pattern consisting of three parts: Model, View, Controller. Model: Handles data logic. View: It displays the information from the model to the user. Controller: It controls the data flow into a model object and updates the view whenever data changes. -It is invented by Trygve Reenskau.

What is model view or controller?

MVC (Model-View-Controller) is a pattern in software design commonly used to implement user interfaces, data, and controlling logic. It emphasizes a separation between the software's business logic and display. This "separation of concerns" provides for a better division of labor and improved maintenance.

What is model of MVC?

The Model is the part of MVC which implements the domain logic. In simple terms, this logic is used to handle the data passed between the database and the user interface (UI). The Model is known as domain object or domain entity. The domain objects are stored under the Models folder in ASP.NET.

What does a controller do in the MVC model?

A controller is responsible for controlling the way that a user interacts with an MVC application. A controller contains the flow control logic for an ASP.NET MVC application. A controller determines what response to send back to a user when a user makes a browser request.


1 Answers

MVC is a loosely defined pattern that gives the architect much discretion over implementation details. This is probably why so many variations of MVC exist.

To my knowledge, it all started with Classic (Original) MVC that separate web application into three parts i.e. Model, View and Controller. The objectives were:

  • Achieve loose coupling between Model and View (Observer pattern employed to achieve it).
  • Encapsulate business logic into Model so that it can be exhaustively tested.
  • Make View as dumb/thin as possible to lessen the need to test it.

A Standard MVC Interaction

The pattern charmed so many that there were several variations (Active Model, Passive Model, Model2). These variations were due to implementations of the pattern in particular frameworks to suit the frameworks' design goals.

For example, one variation is Model2. Model2 is a web variation (Classic MVC was actually targeted for desktop application) and got popular as "ASP.NET MVC Framework".

The Model2 Interaction as in the ASP.NET MVC Framework

The key difference between Classic MVC and ASP.NET MVC Framework is, the later provides a neat separation between Model and View i.e. no direct interaction. Rather Controller is responsible to facilitate this communication between Model and View in ASP.NET MVC Framework. This makes ASP.NET MVC Framework web applications a lot easier & efficient to test.

Furthermore, in Model2 there's a sort of loose contract that can be established between the view and the controller. In the ASP.NET MVC Framework, this contract used to be represented by the ViewData container object and nowadays using a ViewModel object.

To avoid confusion, one need to look at the interactions between these three parts (Model, View & Controller) in the MVC pattern implementations currently in use. Also embrace the fact that it is a particular implementation of MVC pattern and one diagram may not be able to describe it completely.

like image 165
SBirthare Avatar answered Sep 22 '22 18:09

SBirthare