Why MVC Architecture?

Hi guys, in this session we are going to discuss the MVC architecture fundamentals along with its benefits over traditional approach. MVC is an acronym for Model, View and Controller. It’s a product development architecture. The traditional approach of programming works on Input -> Process -> Output approach while MVC works on Controller → Model -> View.

During, traditional approach of programming, the UI coding, business logic and applications data domain was written into a single file which creates lack of maintainability, testability as well as scalability of the application.

With the emerge of MVC approach, it helps you create applications that separate the different aspects of the application (input logic, business logic, and UI logic), while providing a loose coupling between these elements. The pattern specifies where each kind of logic should be located in the application. The UI logic belongs in the view. Input logic belongs in the controller. Business logic belongs in the model. This separation helps you manage complexity when you build an application, because it enables you to focus on one aspect of the implementation at a time. For example, you can focus on the view without depending on the business logic.

MVC Design diagram:

The MVC framework includes the following components:

  • Models. Model objects are the parts of the application that implement the logic for the application’s data domain. Often, model objects retrieve and store model state in a database. For example, a Customer object might retrieve information from a database, operate on it, and then write updated information back to a Customer table in a SQL Server database. In small applications, the model is often a conceptual separation instead of a physical one. For example, if the application only reads a dataset and sends it to the view, the application does not have a physical model layer and associated classes. In that case, the dataset takes on the role of a model object.
  • Views. Views are the components that display the application’s user interface (UI). Typically, this UI is created from the model data. An example would be an edit view of a Customer table that displays UI Controls based on the current state of a Customer object.
  • Controllers. Controllers are the components that handle user interaction, work with the model, and ultimately select a view to render that displays UI. In an MVC application, the view only displays information; the controller handles and responds to user input and interaction. For example, the controller handles query-string values, and passes these values to the model, which in turn might use these values to query the database.

Below are few pros and cons of this architecture:

Pros:

  • Simultaneous development — Multiple developers can work simultaneously on the model, controller and views.
  • High cohesion — MVC enables logical grouping of related actions on a controller together. The views for a specific model are also grouped together.
  • Low coupling — The very nature of the MVC framework is such that there is low coupling among models, views or controllers.
  • Ease of modification — Because of the separation of responsibilities, future development or modification is easier i.e. scalability of the product is increased.
  • Multiple views for a model — Models can have multiple views.

Cons

  • Code navigability — The framework navigation can be complex because it introduces new layers of abstraction and requires users to adapt to the decomposition criteria of MVC.
  • Multiple Representations — Decomposing a feature into three artifacts causes scattering. Thus, requiring developers to maintain the consistency of multiple representations at once.

After above discussion, it can be said that, software development becomes more smoother & robust using MVC architecture in compare to the traditional approach due to its advantages of code reuse, simultaneous application development etc. Now-a-days, all the popular platform of development like .NET, PHP, Java, has facilitates to use MVC architecture.

Show your support

Clapping shows how much you appreciated Socratic Solution’s story.