Understanding MVC with the Help of Design Patterns
Most of us are familiar with the architecture called MVC - Model-View-Controller and how to implement it, but how many of us know that MVC follows compound pattern when seen from a design pattern point of view.
Understanding MVC with Design Patterns
Here we are basically trying to understand MVC from the Design pattern point of view. MVC as the name suggests consists of three major components namely Model, View and Controller. Responsibilities of the classes are given below:
- Model : Holds the Application logic and the associated data.
- View : Responsible for Representing data contained in the Model.
- Controller : Responsible for taking actions based on User Interaction and calling necessary APIs in the Model.
Let us try to understand based on the functionalities of each of these components the pattern they might be following.
Model basically has the application logic and maintains the state of the application and it notifies the View of any change in its state so that the View is updated.
Therefore Model follows the Observer Pattern where it notifies its subscriber (The View) of its change in state.
View basically has the UI components like Window, Text box etc. Therefore UI objects will be composed of multiple smaller UI components which makes it an ideal candidate for Composite Pattern.
Controller on the other hand responds to user actions and tries to handle it by calling necessary APIs in the model based on the UI event. Therefore we can say that the View delegates the responsibility to the Controller to handle user interaction, hence we can say that the Controller implements Strategy Pattern.
Therefore we can say that the MVC is a Compound pattern in action. Understanding MVC in terms of Design Pattern will enable us to know the limitation of using MVC and allows us to visualize the interaction between its components.
Next time if we hear of MVC its easier for us to model the interactions between the components since we now know the design pattern each of the components follow.
Comments
Post a Comment