Any modern-day website consist of a User Interface(UI), and a business logic that modifies data before sending to UI and modifies it again after receiving request from UI.
There are many issues that come while designing websites with complex functionalities. But one important one is “How to modularized the UI functionality so that individual parts can be easily modified”.
Why should we modularize?
* UI changes more frequently than Business logic and hence it makes sense if we separate both of them. We can make modification to UI without affecting and avoiding retesting of Business logic implementation.
* Same Data can be displayed differently on different Views (or Pages), like same data can deliver different graphs. So it will be good to separate View from the Data.
* User Interface can vary across platform while Business logic can still stay the same. Same website can have different UIs for mobiles and computers.
* Generally developing good UI and writing good complex business logic need separate skills, so its better to keep them apart for experts to handle them separately.
What is the solution?
One of the solution is to use Model-View-Controller (MVC) pattern. This pattern separates presentation, modelling and event handling in three separate classes.
Model : The model manages the behavior and data of the application domain, responds to the request for information about its state (from VIEW) and responds to instructions to change state (from controller).
View : The view manages display of the information.
Controller : Interprets input from the user (Mouse/Keyboard) to change the view or model.
Basically Model is the class containing business logic, controller contains event handlers and view have the UI.
Certain things to keep in mind :
* Developers must try to avoid making UI totally agnostic. View is designed to display information provided by a specific Model or set of models. So views and controllers can be dependent on model.
* But reverse must be tried. Keep model independent of view and controller. This model can then serve many views.
* Developers tend to bind UI and model together, putting business logic related to model into the UI code, which leads to unmaintainable applications.
One last thing:
Controller is in charge of processing user inputs and coordinating server-side calls until the view is rendered (in asp.net), however you can also apply this pattern to a stateful client UI technology such as Windows Forms or WPF.
Leave a Reply