Model–view–controller (MVC)

The model-view-controller (MVC) framework is a kind of design pattern for computer software. First developed in the 1970s, MVC is essentially a way of organizing programming code into separate categories based on each part of the code's intended function. Specifically, it distinguishes among the part of an application's programming code that holds the application's data (model), the part that determines the application's appearance (view), and the part that controls how the application functions (controller). In short, MVC architecture is intended to serve as a framework that helps to ensure that an application's coding design is as efficient and effective as possible. It essentially accomplishes this by dividing applications into logical units and separating business logic, or the part of programming that manages the function of an application, from interface logic, or the part of programming that manages the interaction that occurs between the user and the application.

rssalemscience-20170808-246-164166.jpg

Background

Norwegian computer scientist Trygve Reenskaug developed the original MVC framework in the 1970s. At the time, Reenskaug was working at the Xerox PARC research center as part of a team of programmers who were creating an object-oriented, dynamically typed, reflective programming language called Smalltalk. When he wrote his first paper on MVC in 1978, Reenskaug called his breakthrough framework the thing-model-view-editor pattern before settling on model-view-controller. In developing MVC, Reenskaug was trying to create an approach to programming that modeled complex real-world systems like the design and construction of a major airport. While human beings have an internal mental model of such systems, computers have a corresponding digital model. Reenskaug's goal was to find a way of bridging the gap between these two models. His solution was MVC.

The challenge Reenskaug faced in developing MVC was enormous. In the 1970s, desktop computers were in their infancy, and the few that existed were primitive and isolated. Further, these early computer systems allowed for little user input and featured severely limited user interface design. As a result, MVC—a programming model that depends on interaction between user and system—was an idea that was well ahead of its time. Nevertheless, Reenskaug correctly predicted that MVC would eventually be a useful tool in the future of computer programming.

One of the major events that contributed to the eventual widespread adoption of MVC was the gradual emergence of graphical user interface (GUI). In computing, an interface is the system through which a user interacts with a computer. Most early computers featured an entirely text-based interface that required users to type commands and read the computer's response. In the 1960s and early 1970s, programmers began developing computer interfaces that featured graphics as well as text. These became known as GUIs. Although a number of early GUI-based systems were developed in the 1970s, the concept did not gain popularity until the 1980s and 1990s. Once GUIs became the industry standard, MVC came to be seen a valuable tool for creating programs and applications that require a complex integration of functionality, appearance, and interactivity.

Overview

The MVC pattern has three components: model, view, and controller. The model represents the structure of data in an application. In practice, it structures data in a reliable form and prepares it according to the controller's instructions. The view displays data to the user. In short, it is everything that the user can see and interact with on the screen. The controller connects the model and the view and facilitates communication between the two. Specifically, it takes user commands through the view, sends those commands to the model so that the application's data can be updated, and sends instructions back to the view that update the user interface. Together, these three elements form a useful foundation on which to build an application's program code.

For those unfamiliar with the intricacies and technicalities of computer programming, it may be easier to understand what MVC is and how it works when it is described in everyday terms. Imagine, for example, that a customer walks into a sandwich shop and places an order with the sandwich maker. In this scenario, the customer is the user and his or her order is the user request. The customer approaches the counter, addresses the sandwich maker, and orders a turkey club. While the customer thinks of the turkey club as a delicious lunchtime meal, the sandwich maker simply views it as list of steps in a process that he or she needs to complete to produce a finished product. Some of the steps involved in this process may include things like gathering several slices of bread; toasting the bread; spreading mayonnaise on the toasted bread, adding turkey, bacon, lettuce, and tomato; wrapping the sandwich; and charging the customer. In effect, the sandwich maker's brain is the controller. Once the customer (or the user) places an order (or issues a command), the sandwich maker's brain (or the controller) begins the work of fulfilling the order (or responding to the command). The sandwich maker can only use the tools and ingredients he or she has at hand to fulfill the order. Some of these include the toaster, a knife, the turkey, garnishes, and sandwich wrap. Likewise, the controller within an application can only complete a task with the resources that it has access to. These resources are the model. The completed sandwich that the sandwich maker prepares using his or her brain (the controller) with the help of the available tools and ingredients (the model) and delivers to the customer (the user) is the view.

By connecting the separate model, view, and controller components, MVC provides an efficient means of organizing the complicated web of user requests, logic, resources, and interface displays involved in the use and operation of computer applications. Everyone who uses computers, smartphones, tablets, and a wide variety of other devices interacts with MVC-based applications on a daily basis, often without even realizing it.

Bibliography

Baghele, Elvin. "Deep Dive Into Model-View-Controller (MVC) Best Practices and Case Studies." Medium, 14 Apr. 2024, elvinbaghele.medium.com/deep-dive-into-model-view-controller-mvc-best-practices-and-case-studies-c758e13ec4cf. Accessed 7 Nov. 2024.

Chen, Brent. "Polymorphism of MVC-esque Web Architecture: Classification." InfoQ, 15 Sept. 2016, www.infoq.com/articles/mvc-web-architecture-polymorphism#. Accessed 7 Nov. 2024.

Kononenko, Kevin. "Model-View-Controller (MVC) Explained through Ordering Drinks at the Bar." Medium, medium.freecodecamp.org/model-view-controller-mvc-explained-through-ordering-drinks-at-the-bar-efcba6255053. Accessed 7 Nov. 2024.

"Model-View-Controller." Apple, developer.apple.com/library/content/documentation/General/Conceptual/DevPedia-CocoaCore/MVC.html. Accessed 7 Nov. 2024.

"Model View Controller (MVC)." Techopedia, www.techopedia.com/definition/3842/model-view-controller-mvc. Accessed 7 Nov. 2024.

"MVC: Model, View, Controller." CodeAcademy, www.codecademy.com/articles/mvc. Accessed 7 Nov. 2024.

Rouse, Margaret. "Model-View-Controller (MVC)." TechTarget, whatis.techtarget.com/definition/model-view-controller-MVC. Accessed 7 Nov. 2024.

"Understanding Model-View-Controller." Coding Horror, 5 May 2008, blog.codinghorror.com/understanding-model-view-controller. Accessed 7 Nov. 2024.