MVC

Model-View-Controller

A core concept in software architecture called model-view-controller or MVC, is used to dictate the user interface of software applications. This concept is as much a core principle of computer programming as DRY (Don't Repeart Yourself) and thus deserves it's own blog post explanation.

The primary purpose of MVC is to seperate responsibilities of the user interface into three seperate components. It is perhaps easiest to think about this model starting with the view.

The view contains the most updated version of the model and outputs that information to the user in a specified format, i.e. table, text, blog-post, graph, etc. The controller allows the user to send commands or requests to the model to update the model's state. Finally, the model serves as the manager of data and logic. Updates to the model can change the output of the view as well as the commands available to the controller

In this way, the MVC works in unison to manage user interface. as shown in the image below

Let's look at an example

It is always helpful to illustrate a practical example of MVC in action to better understand its principles.

Currently, this blog page is a static website, which means that it is mostly just viewable. It cannot be modified without going in and changing the source code. Sure, you can click on hyperlinks and they will navigate you around my site, but you cannot input any new information to modify its contents

Let's say that I wanted to make my blog more interactive, or at least make it easier for me to write new posts. Instead of having to create an entire html document for each new posts, let's say that I adopted a framework that allowed my site to have a new blog input field.

Now I can use the view to type my new plog post and click the submite button. The controller, which serves as the brain behind my newly fangled MVC interface, would then notify the model to add this new post to the database of blog posts. The framework owuld dictate the format and styling elements to render everything in the same way as my previous posts, and the view would now render my latest blog-post.

Of course, this is actually on my to do list once I learn how to use framework, and actually researching ruby on rails is how I stumbled upon the concept of MVC and decided it warranted it's own tech blog post.

Blog Archive

Coming Soon!