Skip to content

Model View Controller

Choi Geonu edited this page Jul 7, 2016 · 14 revisions

Mode-View-Controller

Definition

Model-View-Controller(a.k.a. MVC) is long-standing design pattern for user interfaces.

It has three important components:

  • Model - is a data manager

  • View - is what user can see

  • Controller - Controller's definition is generally unclear.

    But let's define it clearly at here.

    Controller converts user's inputs to model commands.

By the above definition, this can be illustrated by following chart.

MVC in Wikipedia (from wikipedia)

The following one is not what we want:

Controller with bidirectional data flows makes a lot of side effects that programmers can not control.

So we just make unidirectional data flows for less side effects. Like Flux!

Yes, Flux is a just special case of MVC.

Data Flow

  1. User makes an interaction, and Controller catch that as Event

  2. Controller do some business logic (like HTTP request, database query, ...) and sends Commands to Model. (ex. IncreaseNumber, SaveUserList(users))

  3. Model mutates the State based on Commands and notify the result of mutation View.

  4. View renders State to something that user can see.

  5. User makes an interaction, and Controller catch that as Event

  6. And so on...

See the examples for more details.

Or see Tutorial.

Clone this wiki locally