Skip to content
BENIBIX Learn

Model-View-Controller (MVC)

Development🏗️ ArchitectureArchitecture Styles

Also known as MVC, MVC Pattern, Model View Controller

Splits an app in three: data, screens and the code that links them.

Think of it like

Think of it like a cafe. The kitchen has the food and the counter shows it. The waiter takes orders between them.

Example

On Emma's blog, clicking a post goes to a controller. It asks the post model for the text and hands it to the post view, which draws the page.

Why it matters

It is the shape of many popular web frameworks. Knowing it tells you where to find each part of the code.

Definition

Model-View-Controller, or MVC, splits an app into three parts. The model holds the data and the rules. The view shows the data to the user. The controller takes what the user does, updates the model and picks a view. The idea dates from the late 1970s and is still used by many web frameworks today.

Common mistake

Putting all the logic in the controllers until they are hundreds of lines long. The rules belong in the model.

Key takeaways

  1. 1
    Model. Data and rules.
  2. 2
    View. What the user sees.
  3. 3
    Controller. Turns clicks into actions.

Compare