I am currently working on application, which requires presence of web, desktop, palm and as many as possible kinds of clients. Main advanture in this and similar applications is to make as reusable code as possible. Using Spring as underlying IoC container is not an issue in all clients. Business objects, model and intergration part can be also shared with different setups. Problem, which I identifed in Spring MVC are controllers. Complete controller part of framework relies on HttpServletRequest and HttpServletResponse. If we set aside cookies, http headers and similar things, which are part of HttpServletRequest/Response, HttpSession, ServletContext we can get interface common for all of them. Name it Storage, Cache, whatever. It boils down to set, get, remove and inner dependencies (Request -> Session, Session -> Context).
One approach is to use interface like Controller and implement everything from scratch (CommandController, FormController, Wizard and so on). Problem is that even Controller is fully dependent on Web concepts.
Alternative approach, which I took was to implement Strategies in already existing controllers. SimpleFormController would have SimpleFormControllerStrategy, which will do the same thing, but with no dependencies to Web concepts. In order for this to work, I implemented simple interface called Storage, which contains get, set and remove Object (default implementation goes to HashMap). Request, Session and Context are extended interfaces from Storage and implement inner dependencies. Wrapper for SimpleFormController will take request and wrap it into HttpRequestAdapter, which implements Request interface. Controller Strategies will be called with that request adapter, which contains session adapter and servlet context adapter. This approach will render my controllers independent from web layer, hence reusable in desktop client.
Complete hassle arround the wrappers is to keep functionallity arround creation of commands from request parameters. Everything would be rather simple if only dispatcher servlet would "know" for HttpServletRequest and from that point different kind of adapters to kick in.
Idea came from the fact that desktop clients also have MVC pattern as web clients.
I am still in the phase of getting acquainted with AOP approach. Maybe AOP can offer even simpler solution instead of controller wrappers.
Thoughts?


Reply With Quote