DEV Community

Anja
Anja

Posted on

What is a Model View Controller?

Let`s have a look at MVC, the Model View Controller. MVC is a design pattern for web applications. It consists of these three components:

  1. Model: The model holds all the data, state and application logic. It provides an interface to manipulate and retrieve its state. It responds to requests of the View and instructions of the controller. It also informs the View about state changes.

  2. View: The View receives all the data it needs and displays it in a User Interface. The View can request state information from the model.It also "talks" to the controller by e.g. informing it that the user pressed a button.

  3. Controller: The controller controls the interactions between the model and the view. It sends instructions to the model to change its state based on what has happened (e.g. pressing a button) and requests the view to change its display.

Have you used the MVC yet?

Top comments (2)

Collapse
 
jimcmorrison profile image
JimCMorrison

Nice quick knowledge share Anja! My first entanglement with MVC was with Ruby on Rails. I have a lot of nostalgia for working with Rails but not something I play with much these days. What was your first experience with MVC?

Collapse
 
anja profile image
Anja

Hi Jim! That's great! 😊 I didn't try Ruby on Rails yet. This blogpost of mine is old and transfered from my WordPress, so I don't remember if I only read the theory about MVC back then or did try it already. 😄