长篇连载 ,如何一次通过310-083考试

pass 310-083 (003-design pattern)

上一篇 / 下一篇  2008-09-16 11:36:19 / 个人分类:Certification_SCWCD5

第二种设计模式Front Controller

           概述:利用展示层前端的一个组件(通常是Servlet)来作为一个控制器,来控制逻辑的跳转,还有请求的转发。为了不同的客户端(手机客户端,网络浏览器或者是PDA乃至ATM等)提起的请求来服务,吧相应的请求转发到相应的处理程序。

 

           publicvoiddoGet(HttpServletRequest request, HttpServletResponse response)

                                   throwsServletException, IOException {

                       String requestType = request.getParameter("requestType");

                       if(requestType.equals("add")){

                                   // forward to add component

                       }elseif(request.equals("delete")){

                                   //forward to delete component

                       }elseif(request.equals("update")){

                                   // forward to update component

                       }else{

                                   //forward to default component

                       }

                       response.setContentType("text/html");

                       PrintWriter ut = response.getWriter();

           }

}

 

           应用:对于客户端可以提交起复杂的请求的程序,有可能需要利用front controller设计模式,来实现控制请求转发的统一,这样当以后程序扩展,需要修改业务逻辑或者相应的功能时候,只需要修改控制器来使请求转发到新的功能模块即可。否则每一个相对的模块都需要提供类似的服务的时候,会导致很多组件中,拥有大量的重复代码。这个设计模式可以消除这些重复的代码。

 

           

优点:可以实现控制器的统一,修改具体业务跳转的逻辑只需要修改controller里面的相应代码,不会影响具体的处理组件,也无须修改客户端的代码(客户端始终都是把请求提交给前端控制器)。提高可管理形以及安全性,重用还有扩展.

 

           缺点:对于客户端的每个不同请求,都要经由前端控制器来转发,对于简单的小程序,有可能增加代码工作量。

 

        举例:控制不同客户端访问不同的代码;国际化或者本地化显示资源;对于session的共享控制;页面的转发跳转,log

 

           考试:记住以下的要点,有助于通过考试。

 

Centralizes Control

Improves Manageability of Security

Improves Reusability

A gateway for requests to the system

Reduce complexity of links in JSPs and Servlets.

Dispatches to a view with different response messages.

Promotes cleaner application partitioning and encourages reuse.

Provides an initial point of contact for handling all related requests.



TAG:

 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

我的栏目

日历

« 2009-01-09  
    123
45678910
11121314151617
18192021222324
25262728293031

我的存档

数据统计

  • 访问量: 523
  • 日志数: 10
  • 建立时间: 2008-09-09
  • 更新时间: 2008-09-25

RSS订阅

Open Toolbar