J2EE Design Pattern : Presentation Tier Patterns : Front Controller Design Pattern
|Front Controller Design Pattern?|
It provides a centralized controller for managing the handling of a request.
When the user accesses the view directly without going through a centralized mechanism, two problems may occur as follows:
- Each view is required to provide its own system services, often resulting in duplicate code.
- View navigation is left to the views. This may result in commingled view content and view navigation.
The presentation-tier request handling mechanism must control and coordinate processing of each user across multiple requests. Such control mechanisms may be managed in either a centralized or decentralized manner.
Use a controller as the initial point of contact for handling a request. The controller manages the handling of the request, including invoking security services such as authentication and authorization, delegating business processing, managing the choice of an appropriate view, handling errors, and managing the selection of content creation strategies.
The controller provides a centralized entry point that controls and manages Web request handling.
Non-software Front Controller Example
Front Controller Class Diagram
Participants and Responsibilities
The controller is the initial contact point for handling all requests in the system. The controller may delegate to a helper to complete authentication and authorization of a user or to initiate contact retrieval.
A dispatcher is responsible for view management and navigation, managing the choice of the next view to present to the user, and providing the mechanism for vectoring control to this resource.
The dispatcher uses the RequestDispatcher object (supported in the servlet specification) and encapsulates some additional processing.
A helper is responsible for helping a view or controller complete its processing.
Servlet Front Strategy
This strategy suggests implementing the controller as a servlet. Though semantically equivalent, it is preferred to the JSP Front Strategy. The controller manages the aspects of request handling that are related to business processing and control flow.
|Example of FrontController|