In a Web application, there is a Front Controller, which based on a request, obtains an "action" string and an application controller instance. it then calls the application controller's method:
process(httpRequest, httpResponse, action)
This method, based on the action passed to it, calls one of several
do<action>(httpRequest, httpResponse)
methods.
Each such doAction method:
performs an action on some BO/s then create an object with the view data (viewObj),
then based on the results picks a view (JSP),
sets the viewObj as the value of an attribute in the request,
finally calls requestDispatcher.include
Suppose There is a need to sometimes customize any of the do methods for some customer... in that case the customer contributes a new controller which extends the given controller, and overrides any of the do methods that need to be customized. (Suppose which controller to load is controlled by some configuration)
On the other hand, each doAction method may be written in a class by itself in a Command Pattern, where all these commands extend from a base Command class which implements a Template pattern. The process method of the controller would hold maintain a map of action-to-command and invoke the command. This can also be customized by providing a new Command class, and some configuration change.
So I was wondering, since this is a very common problem in the presentation layer of web applications, there must be a well accepted design pattern that should be followed in this case. In fact the design pattern is not necessarily a JEE only pattern...
So what is the accepted/preferred design pattern in this situation?
Aucun commentaire:
Enregistrer un commentaire