Model-View-Controller (MVC) - Acid Dragons

From Coder Merlin
Within these castle walls be forged Mavens of Computer Science ...
— Merlin, The Coder

MVC 1.png MVC Part 2.png

Background[edit]


Introduction[edit]

Model-view-controller. The software design pattern shocked the world. It is used by various programming languages including Python, Ruby, PHP, and Javascript. I know what you’re thinking, what the heck is MVC, and why is it important to me? The MVC design pattern is essential when developing user interfaces, it is executed by dividing programming logic into three different interconnected elements, the model which includes the logical components, the view, which includes the visual elements, and the controller, which allows the user to interact with the app. A few of the many advantages that come with using the MVC framework include that it allows for a faster development process because multiple programmers can use each component individually, it can provide multiple views, which is in increasing demand, as it allows users to access your application in new ways and it limits the duplicate code, one of the essential rules of programming, lastly, MVC allows support for asynchronous techniques, which allows the programmers to develop an application that loads at a faster rate.

In this lab, we will not only be describing each individual component of the design pattern, but we will be revealing why it is the best model when it comes to software design patterns.

Model[edit]

Model is the component that stores all of the data-related logic that users work with. It can contain raw data, or define essential components of your program. It’s basically what you use to create the program. In easier words, it defines what data is needed and updates it to the controller when the controller asks for that data. The model will not have direct interaction with the view. It will only interact with the controller, which can make the model change.

View[edit]

View is any representation of information in some sort of visual. Multiple views of the same information are possible, charts and tables or images. View is the output which the user can see. Based on the visual information seen by the user, interactions can happen on the controller which changes the model. The view output is constantly updated based on the model. For example, when you open a web page you will see graphics. As you interact with the webpage, you will be making changes to the controller which will change the model which updates the view again. When you click on a new tab, the model gets updated by the controller which takes the user input of a mouse click. Since the model has changed, the model will update the view therefore displaying a new tab.

Controller[edit]

A controller, as hinted by the name, is responsible for controlling interactions that the user will have with a MVC application. The basic action of the controller is to accept inputs and convert them into usable instructions for the model or view. A better understanding of the controller is that the User will use the controller to be able to manipulate the model given certain inputs. The controller can discern the inputs and can optionally validate them. The controller works most closely with the view. The relationship between the controller and view can be described as someone locked inside a closet giving instructions to complete a task outside of the closet. Although the controller is able to provide instructions (inputs) there’s no way of knowing what’s actually occurring from the given instructions. That’s where the view comes into play. The view and controller are often mixed up but a simplified manner to understand the difference is to view the controller as an input and the view as the output.

Conclusion[edit]

The Model-View Controller shocked the world when it came to be. It is more of a concept than physical code and that is why so many systems use it. The MVC design pattern revolutionized the way people code. It made it more organized and efficient while eliminating a world of bugs. Now, many variants of the MVC have emerged and are used to this day.

References[edit]