This blog is in response to people asking me question to explain MVC pattern.
I don try to explain MVC in terms of standard talk of Model, View and Controler and how they interact.
MVC pattern is example of seperation of pesentation from content (decouples models and views)to allow multiple presentations to a same data.
MVC pattern or Microsoft Document/View patten in MFC all are example of this decoupling of tasks of content storage, presentation and content changes.
In Document/View pattern Document represented the data and View represented the presentation of that data. Document/View allows multiple views of the same data. So same data could be seen simultaneously in spreadsheet form, and a chart.
When a user updates one of the views, all the document's views are notified of the updation, and each view updates itself using the latest data from the document. Soething like observer pattern.
MVC brings in one more component in this, i.e Controller, which decouples Model and View by one more abstraction by means of handling user interaction for changing the model.
MVC also similar to Dcoument/View implements the Observer pattern where multiple Views subscibes to Model, any change in the model by one view is transmitted to other views to update itself. However, this subsciption and notification for update is not so straightfoward as in client-server model.
Hence, in web it occurs by means of controller taking changes from screen, updating appropriate model and then displaying screen with updated model.
There is also MVC-I & MVC-II, MVC-I was the old model where there was not any controller but jsp/screens directly interacted with models by means binding, bean iterator etc.
MVC-II brought in Controller, where screen does not directly talk to model but through controller.
Controller also forms important part of web development because controller is the one which handles Get and POSTS request by means of form/view submission. Front Controller can take in request from multiple forms and dispatch request to appropriate models. And returns the appropriate view to the user. Front controller allows the easy management/coordination between multiple pages and models.
No comments:
Post a Comment