Model View Controller (MVC) (framework pattern)

Definition:

Model-View-Controller (MVC) is a popular structure of web application frameworks. It divides the web applications into three components:

  1. Model: models represent tables in the database. The models are called by controllers to provide data from databases or to receive data and store to database.
  2. View: views are templates of displayed webpages. They are used by controllers to create dynamic webpages.
  3. Controllers: controllers are responsible for receiving requests and sending back responses. When a request is sent the corresponding controller gets the necessary information from the request, invokes models to prepare responding data, then combines with views to generate the responding webpage.

 

The MVC model helps programmers to better organize their codes into these three components and test individually.

Analogy:

  • Business report team: a typical business report team consists of three groups of people:
    • A manager responsible for communicating with clients and presenting results.
    • The data team responsible for report data.
    • The graphic team responsible for report layouts.

Examples of MVC framework:

  • Ruby on rails.
  • Django (python)
  • Express (node.js)