A Quick Breakdown of the MVC Design Pattern

Model-View-Controller

ยท

2 min read

What is MVC?

MVC or Model-View-Controller refers to a style of designing software, or "architectural pattern" that separates an application into three main logical components: the Model, the View, and the Controller.

Each component is then able to handle specific aspects of the application. This "separation of concerns" makes the application easier to modify and maintain.

What is the Model and what does it do?

The Model component defines what data the app should contain and handles any changes to that data. It is the only component that interacts directly with the database.

What is the View and what does it do?

The View component is responsible for handling the layout and displays that a user will see. This may include things such as: text boxes, drop-downs, forms, etc.

What is the Controller and what does it do?

Think of the Controller as the brains of the operation. Since the Model and View cannot communicate directly, it acts as a "middle-man" that updates them in response to input from the app's users.

The Controller processes incoming requests (sometimes with the help of a Router component), uses the Model to manipulate a database if needed, and directs the View to render the final output to the user.

Common Questions:

  • Is MVC a programming language? No, it's a style of designing and organizing your software, and can be used with most programming languages.

  • What are the differences between MVC and Web API? MVC is used for developing Web applications that reply to both data and views. While Web API is used for generating HTTP services that reply only as data.

  • What are some disadvantages of MVC? MVC is not suitable for small applications. Implementing MVC sometimes requires deep technical knowledge.

  • What are advantages of MVC? Ideal for developing large size Web applications Making changes in the MVC architecture is very easy because modifications do not affect the entire application.

Resources:

MDN techaffinity GeekforGeeks tutorialspoint

ย