Tuesday, April 2, 2013

What is Model View Controller?



 MVC is a software architecture. It’s a design pattern used to achieve customizability in our application. This design pattern separates an application into three main components: the model, the view, and the controller

View  
Is used to,
  • draw the model
  •  update the model’s display
  • determine which objects are selected.
Ex:- Html , Scripts

Controller
The controller contains the control-flow logic. It interacts with the Model and Views to control the flow of information and execution of the application

Model
The model contains the core information for an application. This includes the data and validation rules as well as data access and aggregation logic. Frequently, a model maps to a database table with the entries in




 Problem Statement

Ø  Employee master screen, which takes Name and Age as inputs and save the same in our database.


The right way to solve this problem is by having a good design pattern in place and make sure that the entire team clearly understands the design and implements the same in their code. We can solve this by doing a layered approach using MVC and Visual Inheritance.


1.       View Layer

Our View /UI layer should only have UI related validations in it. We should not have any Business Logic in to it. This gives us the flexibility to change the UI at any time and we can also have different UI for different customers.

2.       Controller /Director

Controller is the layer, which responds to the events in the UI. For example Save button click on my employee master screen. This layer should act as an intermediate between our View and Model.

3.       Model

This layer has all our business logic. This is the most important layer. This layer will have our core functionality.

4.       Database Operations

All the database operations should be done in the Model base class.

Conclusion
Rather than quarrying in a single code base we separate it to 3 parts. Layering Approach helps us a lot and we need to enhance it to get full customizability.




 More details

Features of MVC

          Separation of application tasks
          An extensible and pluggable framework
                               Good Layering Approach

Benefits of MVC

                              Flexibility -  Easier to create multiple views of same model
          It makes it easier to manage complexity by dividing an application into the model, the view, and the controller.
          It does not use view state or server-based forms. This makes the MVC framework ideal for developers who want full control over the behavior of an application.
          Easy Communication through layers
          It provides better support for test-driven development (TDD).
          It works well for Web applications that are supported by large teams of developers and for Web designers who need a high degree of control over the application behavior