Basic Architecture of MVC
I have given an illustration of each section.
Over the past 20 years, websites have moved from simple HTML pages with incredibly complex CSS to incredibly complex applications. Thousands of developers are working with these complex web applications to make them easier to work with.
Developers use different patterns to spread their projects to make the codes more complex and easier to work with by the most popular of these patterns. MVC is also known as a model view controller which targets a large application. So let’s have a look at a software design pattern of MVC-
Model, View, And Controller
Here a user is requesting a specific page from a server based on a URL. If the user is requesting the server will send all the request all the information to a specific controller.
This controller is responsible for handling the entire request from the client and how it will request the rest of the server so that it acts as an intermediary. Look at the other two model models and it should not contain too much code.
The first thing that happens when a controller receives a request is to ask the model for information based on the request. The model is responsible for handling all the data logic of a request.
This means that the model interacts with the database and saves all the legitimacy of deleting and deleting data.
The controller should never directly interact with the data logic. It should only ever use the model to perform these interactions this means the controller never has to worry about how to handle the data. That it sends and receives and instead only needs to tell the model what to do and respond based on what the model returns.
This also means the model never has to worry about handling user requests and what to do on failure or success all of that is handled by the controller and the model only cares about interacting with the data after the model sends its response back to the controller.
The controller then needs to interact with the view to render the data to the user. The view is only concerned with how to present the information that the controller sends it.
This means the view will be a template file that dynamically renders HTML based on the data the controller sends it the view does not worry about how to handle the final presentation of the data.
But instead only cares about how to present it the view will send its final presentation back to the controller and the controller will handle sending that presentation back to the user. The important thing to note about this design is that the model and view never interact with each other any interactions between the model and the view are done through the controller.
A birthing controller between the model and the view means that the presentation of data and the logic of data are completely separated. This makes creating complex applications much easier this is all just theoretical though.
So let’s look at an example of how this design handles a request.
Imagine a user sends a request to a server to get a list of cats. The server would send the request to the controller that handles cats. That controller would then ask the model that handles cats to returns a list of all cats. The model would query the database for a list of all cats and return that list back to the controller.
If the response back from the model was successful then the controller would asl the view associated with cats to return a presentation of the list of cats. This view would take the list of cats from the controller and render the list into HTML. That could be used by the browser.
The controller would then take that presentation and return it back to the user thus ending the request if earlier the model returned an error instead of a list.
The controller would handle that error by asking the view that handles errors to render a presentation for that error. That error presentation would then be returned to the user instead of the cat list presentation.
As we can see from that example the model handles all of the data. The view handles all of the presentations and the controller just tells the model and view what to do. And that’s three are the basic architecture of MVC.
Patterns in MVC design are one of the most popular design patterns among many design patterns. Every developer should have a basic knowledge about the type of this design and its benefits. Thank you.
Have a great day.