The Front Controller Pattern is used to provide a centralized request processing mechanism, all requests will be handled by a single handler. The handler can do the authentication/authorization/logging, or track the request, and then pass the request to the appropriate handler. The following are the entities of this design pattern.
- Front Controller - A single handler that handles all types of requests for an application, either web-based or desktop-based.
- Dispatcher - The front controller may use a scheduler object to dispatch requests to the appropriate handler.
- View - A view is an object created for a request.
We will create FrontController and Dispatcher as front-end controllers and schedulers, respectively. HomeView and StudentView represent various views created for requests received by the front controller.
FrontControllerPatternDemo, our demo class uses FrontController to demonstrate the front controller design pattern.
Create a view.
Create a scheduler Dispatcher.
Create a front controller FrontController。
Use FrontController to demonstrate the front controller design pattern.
Executing the program, outputting results:
Page requested: HOME User is authenticated successfully. Displaying Home Page Page requested: STUDENT User is authenticated successfully. Displaying Student Page