The front controller design pattern is used to provide a centralized request handling mechanism so that all requests will be handled by a single handler. This handler can do the authentication/ authorization/ logging or tracking of request and then pass the requests to corresponding handlers. Following are the entities of this type of design pattern.
- Front Controller – Single handler for all kinds of requests coming to the application (either web based/ desktop based).
- Dispatcher – Front Controller may use a dispatcher object which can dispatch the request to corresponding specific handler.
- View – Views are the object for which the requests are made.
In this example, FrontControllerPatternDemo simulates a request on our application that FrontController receives passes it to the Dispatcher and the dispatcher sends satisfies the request.
The core idea here is to use the FrontController as the object which will receive all requests and pass them to a Dispatcher object which then will try to satisfy whatever is requested.