1.1.12

Application Controller

P of EAA: Application Controller

Core J2EE Patterns


Problem Domain

Core J2EE Patterns

  • You want to centralize and modularize action and view management
    • You want to reuse action and view-management code.
    • You want to improve request-handling extensibility, such as adding use case functionality to an application incrementally.
    • You want to improve code modularity and maintainability, making it easier to extend the application and easier to test discrete parts of your request-handling code independent of a web container.
Pro Spring Patterns
  • Remove action and view management functionality from the front controller.
  • Deploy pluggable action and view handlers to provide support for different types of page controllers and views
  • Improve the reusability, cohesion, and modularity of the application code.
  • The front controller should be generic and as lightweight as possible.
  • Promote test-driven devleopment by making it possible to run unit tests outside the web container.
My understanding

To put it simple, Front Controller is a very first step of creating a good web application by centralize the controller into one access point, so that we can standardize the web application process flow, create access points to inject reusable components/filters.

However, Front Controller is too simple to most web applications. We need to do more. So we need to think about how to generalize the other part of the system, to make it "better".

Thanks to Front Controller, we can now have a more general MVC model. We can make sure that the centralized Front Controller, such as Spring Dispatcher Servlet, decouple the web request and many web specific technologies out of the scope of the design, so that we can think in a more generic way, an application way.

After Front Controller, it is not difficult to put the rest of process into two pars: Action Handling and View Handling. The application works through the request and does everything according to the request on the server side, such update database, create session information, update some distributed services, etc. This is the action part. After that, the application needs to response the client with appropriate data with appropriate format. Usually it would be HTML page, but sometimes, it could be something else.

When considering the action part, it could be very complex. But most of the cases could be defined as a chain of execution. Then we can see that the HandlerMapping interface of Spring makes sense:
  • It uses some request properties to locate an execution chain.
Even though it won't cover all cases, but at least, it would help most of the case. This design is good enough.



No comments: