What are some of the frameworks that follow MVC architectural pattern?
Over the years websites has changed a lot from simple to more complex applications with thousands of developers working on them. To make working with those applications much easier, developers use different patterns to layout their projects and make the code less complex to work with. That's why one of these popular patterns is considered MVC also known as Model-View-Controller.
The goal of this pattern is to spread a large application into specific sections that all have their own purpose.
Model: Handles the data logic and interacts with the database.
Controller: Handles request flow from user interaction, works with the model and selects a view to render the UI.
View: Dynamically renders and displays the application's user interface (UI).
Laravel
Permalink to "Laravel"Laravel is a PHP-based framework that follows the MVC pattern on building applications. It handles routing, caching and authentication without loosing functionality. It has its own template engine called blade with a simple syntax that is easy to learn. Blade contains HTML with some injectable PHP-like syntax. Laravel also comes with its own CLI called artisan. Artisan is a command-line interface which stands at the root of the application and provides a list of commands that can help for developing a web application. Laravel has a file called web.php where you can handle all the requests when users visit the application. In this file, you can link the routes to the controllers which complete user actions and manage the logic of the app. Laravel is a good framework to get started with as it has a simple, comprehensible documentation and a large community to draw from.
Angular.js
Permalink to "Angular.js"Angular follows a component-oriented architecture. Having said that, Angular does share some of the concepts of MVC.
Angular can use the MVC architectural pattern for building web apps. It is designed to be modular. Modules are the building blocks of Angular where code is self-contained and easy to maintain. It is built upon several types of modules which are: components, directives, services and pipes. Angular has its own CLI which assists and generates building blocks such as components, modules or services. It offers a two-way data binding that makes the model and view work with each-other in sync, so when a change occurs it is automatically updated.
Django
Permalink to "Django"Django is a Python web framework which follows the MVC pattern. However, Django uses the same functionality but on a different way making it a little bit confusing on what happens at each layer. This approach is referred as MVT (Model-View-Template).
So, Model serves for the data that comes from the database and that can be linked with the Model object with entities. Templates are normal HTML,CSS and Javascript files but also it will have a DTL (Django Template Language). So, if you want to introduce some dynamic data in your page, then that can be done with the help of the DTL. Therefore, the data will be coming from the Model object. Django workflow goes like this, user requests the data, the request goes to Django framework, after that in Django whenever you create a project you will get a very specific file which is called URL. So, in URL you do all the mapping, from where you get the request and sent it to the View. The business logic which we want to write will be done in the View (weird, right?). It sounds tricky because View is normally referred as a representation of a page but in Django that's not the case as it is represented as the layer where business logic happens. View will use the Model object and the Template too. In other words it will serve as a bridge between them. As a result, the data that needs to be sent to the Template has to be decided by the View and the connection with the Models will be done through the View. So, that's the importance of the Model-View-Template. So, with MVT the sections are segregated by which the Model will work with data, Views will work with logic and Template will work with layouts. It might sound confusing but what differs from MVC is that View represents the business logic and the Controller is omitted because it's part of the framework. On other frameworks we have to configure the Controller as well but in Django there is no need for that as it will be done by the Django framework itself.
Ruby on Rails
Permalink to "Ruby on Rails"Ruby on Rails also uses the MVC architecture. Each component of the model, view and controller resides within the app directory. The role of the Model in the Ruby MVC architecture plays the ActiveRecord
module which serves to handle the business logic and communication with the database. It is designed to create connection with the database, retrieve data from tables or store new information in the database. Then comes ActionController
, the component which handles browser requests and facilitates communication between the Model and the View. Therefore, it can retrieve data from the Model and can pass it to the View, collect information and then use that to update or create a new one in the Model, handling particular requests etc. Lastly, comes the View which contains HTML code mixed with Ruby code to make the page more dynamic. The Ruby code is embedded in HTML using the Ruby syntax called ERb which is wrapped in special tags <%= %>
.
Spring
Permalink to "Spring"Spring is a Java framework for web applications that provides flexibility that you can change anytime.
It follows the Model-View-Controller design pattern. Spring works with the help of a DispatcherServlet
which is a class that receives the incoming requests and maps it to the right resource such as controller, model and view. Spring has its own built-in server therefore it doesn't need a external server activation.
Spring workflow is comprised of these approaches. First, the request is sent to the dispatcher servlet which consults the handler mapping from which it is sent to the controller. The controller takes the request and returns the response with business logic(model) and view back to the dispatcher servlet. Then, the DispatcherServlet
sends view to the view resolver and finally it is sent to the view which the output will be presented. Basically, Spring workflow works in a way that the request is obstructed at DispatcherServlet
which works as a front controller and then forwards the request to the aforementioned modules. When it comes to views, Spring supports many types of views for different platforms. Some of them are: JSP(Java Server Pages), HTML, PDF, Excel, XML, JSON, XSLT etc.
Benefits of MVC
Permalink to "Benefits of MVC"As mentioned in this blog, various popular frameworks follow the MVC design pattern. MVC architecture remains as a great popular pattern used for web application development as it comes with a lot of advantages such as reusability, decoupled code by dividing an application into three units, parallel development meaning that various components can be developed parallelly and also multiple view support.