Name
Front Controller
Goal
Create a single, central component to perform common functions (Figure A-3).
Participants
- Front controller
Singleton object that intercepts all requests and performs common functions.
- Page controllers (or Actions)
Process user input, update the model, and choose views.
- Model
Store application state data.
- Views
Transform model data into a form appropriate for display to the user (Figure A-4).
Figure A-4. Interactions in the Front Controller pattern
Interactions
The front controller intercepts all requests and performs common functions such as logging or decryption. The front controller chooses and forwards the request to a page controller. The page controller parses user input, and translates it into appropriate updates to the model. The model applies business rules and stores the data persistently, either locally, in the business tier, or using some other remote persistence mechanism. Based on the model changes and user input, the page controller chooses a view. The view transforms the updated model data into a form suitable for the user.
Notes
In J2EE, the front controller is typically implemented as a servlet, although in some cases it may be implemented as a servlet filter.
Get J2EE Design Patterns now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.