MVC (Model-View-Controller) architecture pattern is a concept in software programming which divides the program into three parts Model, view and controller. Almost every programming language and their frameworks use this concept to build User Interface applications.
MVC is used to present the logical and factual data to the user and it works as full-stack. By far developers using this pattern to create Graphical User Interface (GUI) applications. Now, MVC has become the most popular architecture design to design web and mobile application because the famous Frameworks like React, Angular, Django follow this architecture.
Though there are many other design patterns, only MVC providing a real-world Solution and it is termed as “Core of the solution’, that’s why more and more frameworks and language adapting this Architecture.
MVC came in existence in the 1970s by Trygve Reenskaug he introduced MVC into Smalltalk-76 (Dynamic object-oriented programming language). MVC gained its first popularity from the Web Application of NeXT’s WebObjects in 1996.
Though MVC was designed to developed desktop computing but with its success in Web applications, WWW adapts it as one of its designed architectures.
Let’s understand the MVC components:
MVC is divided into three parts:
It is the central part of the Architecture that linked with both View and controller. The model component the main logic of the programme it is a collection of rules & function and gives a proper structure to the data which it gets from the controller. It has nothing to do with the user interface it works on the back end.
As it linked with view and controller, so it gets a request from view to show the result and it itself request the controller to get the data. It could be considered as the brain of the MVC structure.
The view is that part of MVC which interact with the user and used to present the structure or result form by the model.
As view is a representation of Model data, but first view request model for the results to show, then Model accepts the request and give a result to the view in a particular format. The view can represent the Model result in the form of Graphical interface and it could be graphs, Graphical text, boxes, etc.
Controller also deals with the user interface it basically handles the user request. Almost every application collects data from the user that’ show a user can interact with the application here controller play its part controller grab the request from the user and provide it to the Model.
When a user gives some data or request something the controller sends a command to the Model to provide some logic on it.
Points to Remember:
- The model gives a proper structure to data and forms an Informational result.
- The view is used to present the Models result in a proper manner.
- Controller interacts with the User input and provides it to the Model so the Model can perform an operation on it.
- Decouple various components
- It provides control over the HTML
- SEO friendly
- A developer can work parallel on different Component of MVC.
- It increases the code reusability
Some Popular Frameworks Follows MVC Architecture:
- Ruby on rails
- Django (Python Framework)
- Symphony (PHP Framework)
- CakePHP (PHP)
- Laravel (PHP framework)
- CherryPy (Python Framework)
Some Advantages and Disadvantages of MVC
- Parallel development because of three components
- Ease in component Testing
- It reduces the complexity among the three components
- Easy to maintain the programme.
- All the logical aspects of the MVC can be controlled together.
- Provides low coupling among Models, View, and Controller.
- Models can have multiple Views
- It provides Support for the Test-Driven Development.
- Models with multiple views can be complex.
- With the increase of Data, it also increases the complexity of the Architecture
- It acts as Full stack so, the developer should have knowledge of Multiple technologies
- MVC is an old Architecture with Morden interface it been difficult to use it.