What is a Model-View Controller?

Model View ControllerIf you’re just getting started in Web design, you’ve probably heard the term model-view-controller, or MVC, being used by other developers. MVC is the most commonly used software design pattern in application development, because it deals with data being accessed and altered by the user through a graphical interface.

An Explanation of MVC Programming

There are three software layers in MVC architecture, and they’re aptly named the model, view and controller layers, according to Apple. The model layer covers all the data that is stored in a static file, such as a database table, and the view layer covers all the code that deals with the graphical user interface, or GUI. The controller is a programming abstraction that covers all the code used to access data from the model. For example, when a user selects a choice from a list displayed on a Web page, such as a list of forum threads, the Web app responds to the input by invoking controller code to query the database for the forum thread. Then, it looks up the URL containing the thread and displays it in the view.

Keeping these layers of code separate is a software engineering technique intended to make maintenance and debugging much easier, and it helps make source code easier to understand for other developers on a team. Virtually all Web applications use MVC, because most websites these days are dynamic programs as opposed to the static HTML pages of the 1990s. There are still some examples of static HTML pages that don’t use MVC programming, but these sites are simple pages that are just meant to be used as digital business cards for small businesses.

How the Layers Work Together

There are different programming languages associated with each layer of the framework, and in general, these languages are interchangeable between frameworks. Most frameworks are compatible with all the major SQL languages, such as MySQL, PostgreSQL, SQLite and Oracle, and all frameworks use HTML, CSS and JavaScript for the view code. However, some frameworks have their own versions of the view layer, which is also called the template layer. Django uses a custom version of the MVC architecture that its developers call MTV, or model-template-view. This framework has its own template programming language based on HML, CSS and JavaScript, and instead of being called the view layer, it’s called the template layer.

In Django, the controller is called the view because the controller is what actually determines how the page is going to look. The template code is essentially static, and the controller code fills it with data from the model layer. Therefore, the Django developers argue that the most significant influence on the way a website looks is the change in data populating a page. The template code is responsible for the visual theme of a website, such as Reddit or Craigslist, but the controller code is responsible for the text displayed on each page. It’s this difference in the information displayed on each page that plays the most significant role in the modern Web.

Related Resource: Python

The World Wide Web is one of the most important forms of media in modern times, and people depend on dynamic Web apps for receiving their information on a regular basis. Without model-view-controller software architecture, Web application design might not be as elegant.