MVC architecture dilemma.

                                                                         
One of the most known and used pattern of the presentation layer of web applications in many platforms and technologies is a Model View Controller pattern. I have worked as software developer in many projects building complex web applications based on JEE architecture, and the following dilemma was quite often present.

Having one controller, dealing with different logic, to satisfy a considerable range of views and models logic, with specific functions for each page, result on complex controller, that with time become error-prone, time consuming and hard to maintain.
On the other hand, building an entire new controller for each screen does not just mean lots of classes, it makes the application harder to extend. If we wanted to build a logging mechanism, for example, we would have to add logging code to each controller separately. In fact, there are lots of things we might need to do for every request: implement navigation, maintain session information, and gather statistics, to name a few.


A pair of patterns helps balance these two approaches. The Front Controller pattern advocates building a single controller that performs common functions on each request, but delegates other functions to a page-specific controller. 




The Decorator pattern then shows how to dynamically expand the front controller. The Front Controller pattern is stand for a controller that has a fairly simple role, it deals with common tasks, and then forward control on to a page-specific controller. 
The specific functions of updating the model and choosing the view are delegated to a page-specific controller


Comentarios