Front Controller Design Pattern

The front controller design pattern means that all requests that come for a resource in an application will be handled by a single handler and then dispatched to the appropriate handler for that type of request. The front controller may use other helpers to achieve the dispatching mechanism.

UML Diagram Front Controller Design Pattern

Design components

  • Controller : 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.
  • View: A view represents and displays information to the client. The view retrieves information from a model. Helpers support views by encapsulating and adapting the underlying data model for use in the display.
  • Dispatcher: 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.
  • Helper : A helper is responsible for helping a view or controller complete its processing. Thus, helpers have numerous responsibilities, including gathering data required by the view and storing this intermediate model, in which case the helper is sometimes referred to as a value bean.

Let’s see an example of Front Controller Design Pattern.

Java





Output:

Requested View: Teacher
Authentication successful.
Teacher View
Requested View: Student
Authentication successful.
Student View

Advantages :

  • Centralized control : Front controller handles all the requests to the Web application. This implementation of centralized control that avoids using multiple controllers is desirable for enforcing application-wide policies such as users tracking and security.
  • Thread-safety : A new command object arises when receiving a new request and the command objects are not meant to be thread-safe. Thus, it will be safe in the command classes. Though safety is not guaranteed when threading issues are gathered, codes that act with the command are still thread safe.

Disadvantages :

  • It is not possible to scale an application using a front controller.
  • Performance is better if you deal with a single request uniquely.

If you like w3wiki and would like to contribute, you can also write an article using

write.w3wiki.net

or mail your article to review-team@w3wiki.net. See your article appearing on the w3wiki main page and help other Beginner.


Contact Us