MVC Framework
MVC stands for Model-View-Controller and it separates an application into three logical components: the model, the view, the controller. It separates the business logic and presentation layer from each other. MVC architecture has become popular for designing web applications as well as mobile applications these days.
History of MVC Architecture:
-
MVC architecture first discussed in 1979 by Trygve Reenskaug while visiting the Xerox Palo Alto Research Center (PARC)
-
The MVC model was first introduced in 1987 in the Smalltalk programming language.
-
MVC was first accepted as a general concept, in a 1988 article in The Journal of Object Technology (JOT).
-
Nowadays, MVC pattern is widely used in modern web applications
Important components of MVC:
Model: The Model component deals with data-related logic that the user works with. For example, a user object will retrieve the user information from the database, manipulate it and update it data back to the database or use it to render data.
View: A View represents the presentation of data. For example, the User view will include all the UI components such as text boxes, dropdowns, etc. that the final user interacts with. Views are created by the collected data from the model. A view requests the model for information so that it resents the output presentation to the user.
Controller: Controllers act as an interface between the Model component and View component to process all the business logic and incoming requests, manipulate data using the Model component and interact with the Views to render the final output. There is no doubt Controller is the brain of the entire MVC system. For example, a controller can update a model by changing the data related to a character in a video game. It may modify the view by displaying the updated data of the character in a video game.
Let's take an example of a car to define MVC:
Model - Storage ( Petrol or Diesel tank)
|
View - User interface : ( Gear lever, panels, steering wheel, etc.)
|
Controller - Mechanism ( Engine)
|
Engine runs using user interface devices and takes fuel from storage which helps it to run the car.
Advantages of MVC:
-
MVC Model components can be tested separately from the user.
-
The development of the various components can be performed parallelly.
-
It helps you to avoid complexity by dividing an application into the three units Model, View, and Controller.
-
Search Engine Optimization (SEO) Friendly.
-
All classes and objects are independent of each other so that you can test them separately.
Disadvantages of MVC:
-
Difficult to read, change, to unit test, and reuse this model.
-
No formal validation support.
-
Increased complexity and Inefficiency of data.
-
Difficult to use with the modern user interface.
-
Knowledge of multiple technologies is required.
Summary:
-
The MVC is an architectural pattern that separates an application into Model, View, and Controller.
-
Model: Responsible for maintaining data and its business related logic.
-
View: Responsible for the representation of data to the user.
-
Controller: Controls the interactions between the Model component and View component.
-
MVC is a highly testable, extensible framework.
-
Some popular MVC frameworks are Rails, Zend Framework, CodeIgniter, Laravel, Fuel PHP, Django, Ruby on Rails, etc.
nice
Leave a Reply
nyc
Leave a Reply
nyc
Leave a Reply