No, your web framework is not MVC

Whilst it is theoretically possible, I've yet to see a single server-side web framework that is MVC.

"Oh, pshaw!", I hear you say, "But {framework of choice} says it is! So it must be!"

Yeah, and MySQL says it's a good DBMS...

What is MVC?

MVC - Model / View / Controller - is a design pattern for GUI applications to affect "separation of concerns". This allows each part of the application to be loosely coupled, improving isolation, and enforcing adherence to interfaces.

The Model provides interfaces to the state of the application and whatever data it accesses.

The View subscribes to changes in the Model, and presents the information in a meaningful way to the "user".

When the user interacts with the View, it sends actions to the Controller, which performs the work, and (in most cases) updates the application state by changing the Model.

And around it goes. Model changes state, View updates, etc. Changes and updates always move in the same direction, and each component is only directly influenced by the previous in the circle.

Yeah, so why isn't {my framework} MVC?

OK, so most server side frameworks are generally:

  • Use clicks link / presses button / etc.
  • HTTP request is routed via URL patterns to a handler
  • handler consults the DB for state
  • handler generates a response using Templates
  • handler returns response to User.

Can you see the difference here?

The handler is involved in almost every step. Instead of a loop, we have:

User actions are sent to the Handler, which we might equate to the Controller.

And then the Controller affects changes to the DB, which is our Model.

All fine so far.

Except, our "view", which is the web browser, is not updated from our model.

The Handler renders a Template using the updated Model state, and passes that to the browser.

It's a subtle but important difference, and this pattern is known as "Model / View / Adapter", or also "Model / View / Mediating Controller", as the "controller" mediates between the View and the Model.

You can read more about it here

Aren't you just quibbling?

Well, no, not really (OK, a little bit :).

Firstly, it's important to understand the differences to see why MVC works great on modern JS frameworks.

But also, like the folly and abuse of the "nosql" term (where people mean non-relational), it's causing people to focus on the wrong features of the solution. The goals of each part of a MVC and MVA system are different.

comments powered by Disqus