Skip to content

Model View Controller

Choi Geonu edited this page Jul 6, 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 - Yeah controller's definition is unclear. But let's define it clearly just for RxMVC

    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:

MVC in Wikipedia

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...

So, can we build an application with this pattern?

See the examples.

Or see how to do that

Clone this wiki locally