What is MVC?

What is MVC?

MVC or Model View Controller is a design pattern. This design pattern has been present in software applications for several decades. The Model View Controller pattern was invented in a Smalltalk context for decoupling the graphical interface of an application from the code that actually does the work.

Model: Consist of Application data and the business rules. It contains the code to manipulate the data ( From Database or any datasource) & Also the Objects that retrive the data. It represent the state of particular aspect of the application. Eg Model Maps to Database Table and entries in table represent the state of the application.Model is responsible for actual data processing, like database connection, querying database, implementing business rules etc. It feeds data to the view without worrying about the actual formatting and look and feel.

Controller: Handles user interation, Reads data from view, Controls Input & Send input data to the model. Handles Inputs and update the model to reflect the change in state of the application. It also pass information to the view . Controller is responsible for Notice of action. Controller responds to the mouse or keyboard input to command model and view to change. Controllers are associated with views. User interaction triggers the events to change the model, which in turn calls some methods of model to update its state to notify other registered views to refresh their display.

View: Is an output , It could be a webpage or a printout . In short views are used to display the data. Most of the time we create views from the model data. It accepts information from the controller and displays it. View is the graphical data presentation (outputting) irrespective of the real data processing. View is the responsible for look and feel, some custom formatting, sorting etc. View is completely isolated from actual complex data operations.

Advantages of MVC?

1. Separation of Concerns

2. Better Support For Test Driven Development

3. Clean URL

4. Better For Search Engine Optimization

5. Full Control Over the User Interface or the HTML

6. Loosely Coupled so Each Component can be tested independently.