The root cause of writing Software is simple Software solves problems. We analyze the requirements and break them into smaller problems (modules) and then write the solution for each such problem. Every line of code (LOC) we write is meant to resolve some problem. A pattern or design pattern defines how we solve problems, we must remember that a pattern is never the solution itself it is a way solution is written or developed or rather architected.
Around the world developers and solution architects are always excited about using MVC in fact the developer community often frowns upon those who don’t use it! I remember one of friends who once asked me… “OMG! You are not using any MVC of framework? Just writing native code?”… I tried hard to reason… “We may not be using MVC but we are using patterns and its pure OOP, I don’t think such application really requires MVC!”… “No… No… I think you must!”… I resigned!
What exactly MVC has to offer:
- Reduced Code complexity
- Code reusability
- Increased flexibility
- Decoupled code
Have we ever thought? MVC cannot solve the Code complexity or reusability or even flexibility problem, it’s the developers who can solve these problems. Writing decoupled code is also a developer’s thing; a pattern like MVC will create and environment with certain restrictions and rules but the code has to be written by a developer, the logic behind the code has to be thought out by a human!
Before I begin talking in favor of MVC let me clarify that MVC is a pattern, not a solution. It stands in line with all the other patterns like Adapters, Factories, Singletons, Modules, Interpreters, Observers… and so on.
What is MVC?
MVC is much more than a three-letter acronym, which stands for Model-View-Controller; it has become something of a standard in modern web application designs because most of the web applications can be split into the same three tiers MVC has to offer; presentation (View), business logic (Controller) and data access (Model). At the heart of MVC lies the concept separation of concerns or separated presentation, which creates a separation between the domain objects and the GUI elements (user interface).
- Model – It constructs the central component of the MVC pattern, application attributes and behaviors are contained in the Model, and hence they hold the business logic of the application.
- Controller – It controls the application interactions; it sends commands to the Model to update Model’s state and it can also send commands to the View depending upon Model’s response.
- View – It is the user interface or GUI, which is presented to the end user who is completely unaware of the back end operations or any application. It collects data from the end user and sends to the Controller for processing and takes back processed data from the Controller to represent it back to the end user.