Templates by BIGtheme NET

Front Controller

Front Controller
Description:
The beauty of front control design pattern is single point of contact for all requests and responses.

Why do we required:
As a good application designer, we need to concentrate on few common things,
1) Application consistency we call as robustness
2) Less cost of application maintenance
3) Easy to extend (extend ability)
4) No code duplication
5) No duplication of authentication
6) Support multiple languages
7) Support multiple devices
8) Support multiple environments
9) User extend ability

How can we achieve all this with help of FC design pattern:
1) The common logic should be separated as utils, that can be used across all the application.
Using FC, whatever the common logic that all related to request and response should be separated into common place.

The logic related to identify the device type, rendering the page depends on device type, authentication, authorization, common lists that should be loaded depend on role/authorization, cache management depends on role (suppose for managers we want to assign more cache to ensure that application is faster), even we can call AD (Active Directory) for authentication, refresh some user data in cache depends on some conditions.

2) Because of this separation of application cost will be less, once the development is completed. mostly no need to frequently changes all the mentioned areas.

3) We can provide the privilege to customer to extend the AD or use their own AD server to do the authentication or can use cluster servers to do AD also.

4) We should have device identification, processing and user preference language setting related code all at one place.

Sample Source Code:

public class FrontController {

    public static void main(String[] args) {

        FrontController frontController = new FrontController();

        if (!frontController.isTheRoleIsIdentifiedByADServer()) {
            System.exit(1);
        }

        if (!frontController.isAuthenticUser()) {
            System.exit(1);
        }

        if (!frontController.checkDeviceType()) {
            System.exit(1);
        }

        convertTheRequest();

        processTheRequest();

        convertTheResponse();
    }

    static private boolean isTheRoleIsIdentifiedByADServer() {
        System.out.println("AD Authentication");
        return true;
    }

    static private boolean isAuthenticUser() {
        System.out.println("User is authenticated successfully.");
        return true;
    }

    static private boolean checkDeviceType() {
        System.out.println("Is request coming from authorized device or not");
        return true;
    }

    static private void convertTheRequest() {
        System.out.println("Convert the request, so that it can be processed by the application");
    }

    static private boolean processTheRequest() {
        System.out.println("Logic that process business request");
        return true;
    }

    static private void convertTheResponse() {
        System.out.println("Convert the response, so that it can be processed by the client (any device or browser)");
    }
}