6.32. Front-end controller mode

发布时间 : 2025-10-25 12:24:44 UTC      

Page Views: Stats unavailable

The front-end controller pattern (Front Controller Pattern) is used to provide a centralized request processing mechanism, and all requests will be processed by a single handler. The handler can do authentication / authorization / log, 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 from an application, either web-based or desktop-based.

  • 调度器(Dispatcher) -the front-end controller may use a scheduler object to schedule requests to the corresponding specific handler.

  • 视图(View) -views are objects created for requests.

6.32.1. Realize

We will create FrontController Dispatcher As a front-end controller and a scheduler, respectively. HomeView And StudentView Represents various views created for requests received by the front-end controller.

FrontControllerPatternDemo Our demo class uses the FrontController To demonstrate the front-end controller design pattern.

前端控制器模式的 UML 图

6.32.2. Step 1

Create a view.

HomeView.java

publicclassHomeView{publicvoidshow(){System.out.println("Displaying Home
Page");}}

StudentView.java

publicclassStudentView{publicvoidshow(){System.out.println("Displaying
Student Page");}}

6.32.3. Step 2

Create a scheduler Dispatcher.

Dispatcher.java

publicclassDispatcher{privateStudentViewstudentView;privateHomeViewhomeView;publicDispatcher(){studentView=newStudentView();homeView=newHomeView();}publicvoiddispatch(Stringrequest){if(request.equalsIgnoreCase("STUDENT")){studentView.show();}else{homeView.show();}}}

6.32.4. Step 3

Create the front controller FrontController.

FrontController.java

publicclassFrontController{privateDispatcherdispatcher;publicFrontController(){dispatcher=newDispatcher();}privatebooleanisAuthenticUser(){System.out.println("User
is authenticated
successfully.");returntrue;}privatevoidtrackRequest(Stringrequest){System.out.println("Page
requested:"+request);}publicvoiddispatchRequest(Stringrequest){//记录每一个请求trackRequest(request);//对用户进行身份验证if(isAuthenticUser()){dispatcher.dispatch(request);}}}

6.32.5. Step 4

Use FrontController To demonstrate the front-end controller design pattern.

FrontControllerPatternDemo.java

publicclassFrontControllerPatternDemo{publicstaticvoidmain(String[]args){FrontControllerfrontController=newFrontController();frontController.dispatchRequest("HOME");frontController.dispatchRequest("STUDENT");}}

6.32.6. Step 5

Execute the program and output the result:

Page requested: HOME
User is authenticated successfully.
Displaying Home Page
Page requested: STUDENT
User is authenticated successfully.
Displaying Student Page
Principles, Technologies, and Methods of Geographic Information Systems  102

In recent years, Geographic Information Systems (GIS) have undergone rapid development in both theoretical and practical dimensions. GIS has been widely applied for modeling and decision-making support across various fields such as urban management, regional planning, and environmental remediation, establishing geographic information as a vital component of the information era. The introduction of the “Digital Earth” concept has further accelerated the advancement of GIS, which serves as its technical foundation. Concurrently, scholars have been dedicated to theoretical research in areas like spatial cognition, spatial data uncertainty, and the formalization of spatial relationships. This reflects the dual nature of GIS as both an applied technology and an academic discipline, with the two aspects forming a mutually reinforcing cycle of progress.