How Principles of Software Engineering are Seen in the MVC Framework

Danielle Leppert-Simenauer
4 min readJan 26, 2021
Model-View-Controller Diagram

Model-View-Controller (MVC) is one framework for building web applications. It follows several principles of software engineering that make it so successful. Here I lay out the MVC framework, several software engineering principles, and the connection between the two.

The MVC Framework

Let’s take a second to go over what each part of the MVC covers:

  • Models: The backend of the application. This is where all the data manipulation happens. These files will consist of Python, Ruby, etc.
  • Views: The frontend of the application. These files consist of HTML, CSS, etc. This is the only part the user interacts with directly.
  • Controllers: Connects the frontend, or views, with the backend, models. The controller takes the user input and sends it to the model (What Is Model-View and Control?).

A great analogy I’ve read is that if the application is a restaurant, then the models are the cooks, the views are the customers, and the controllers are the servers.

Each part of the MVC framework has its own responsibility. A sample request goes as follows:

  1. An HTTP request is made by entering a URL into the browser.
  2. The HTTP request is sent to the server.
  3. The application’s router takes that request, interprets it, then sends it a message to the controller mapped in the route.
  4. The controller takes that message and sends it to the view file that was mapped to the controller method.
  5. The HTTP response containing the view page is returned by the server.

The fact that each part of the MCV framework has its own responsibility leads nicely to the principle of separation of concerns.

Separation of Concerns and the Single Responsibility Principle

The principle of separation of concerns, or modularity is the principle that concerns should be separated into modules (named and addressable components) in an application. The single responsibility principle is very closely related and is the idea that each of those modules should have only one responsibility.

The models are responsible for the logic and data manipulation. The views are responsible for interacting with the user, and the controllers are responsible for communicating between the models and the views. Each responsibility belongs to one part of the application and one part alone.

Abstraction

Each module should hide all of the nitty-gritty that goes on inside of it, while making available the relevant inputs and outputs that matter to its connecting modules. This is called abstraction. Timothy Budd writes, “Abstraction is the purposeful suppression, or hiding, of some details of a process or artifact, in order to bring out more clearly other aspects, details, or structure” (Budd 2002). Here’s a great analogy I once heard. When you press the gas pedal in your car, a lot happens under the hood between that event and the event of your car moving forward. Yet, you don’t need to know everything that goes on under the hood in order to move forward. What goes on under the hood has been abstracted away from the driver. With programs, modules should be designed so that whatever is going on in that module should stay “under the hood” of that module and only the information that is relevant, whether for being inputted into another module or being outputted to the user should be outputted.

There’s a lot that goes on “under the hood” of the models, views, and controllers. Yet, however much that goes on deep in the code does not reach the surface. Not all the details that go on inside the models get passed on to the controllers and vice versa. The same goes for the controllers and the views and vice versa. Because all of the nitty-gritty is abstracted away in each module, information can be passed simply between the different components of the MVC framework.

Conclusion

Because MVC follows software engineering principles, MVC allows for simultaneous development, reusability, improved scalability, and better extendability (What Is Model-View and Control?). These are all great things that should be found in any great application. The MVC pattern is helpful to website application development in part because it follows software engineering principles. Each piece of the puzzle has its own role and responsibility that it not shared with other pieces of the puzzle.

Citations

What Is Model-View and Control?, Visual Paradigm , www.visual-paradigm.com/guide/uml-unified-modeling-language/what-is-model-view-control-mvc/.

“Chapter 2: Abstraction.” An Introduction to Object-Oriented Programming, by Timothy Budd, vol. 3e, Addison-Wesley, 2002, pp. 25–25.

--

--