The MVC pattern

The MVC pattern is a way of working that makes it possible to differentiate and separate what the data model is (the data that the app will have that is normally stored in DB), the view (an HTML page), and the controller (where the requests of the web app are managed).

The MVC is a pattern for software development that is based on separating the data, the user interface, and the logic of the application. It is mostly used in web applications, where the view is the HTML page, the model is the database manager system and the internal logic, and the controller is responsible for receiving the events and solving them. Let's explore each element in more detail:

For a detailed understanding for the use of the MVC model, let's look at its control flow:

  1. The user activates an event in the interface (for example clicking on button, link)
  2. The controller receives the event and manages it
  3. The controller consults or modifies the model
  4. The controller sends the response to the interface and it reacts depending on it (changes the screen, opens a link, and so on)
  5. The interface waits for a new user action

In the following diagram, we can see the steps we just described:

Among the advantages that this pattern provides us, we can highlight the following: