`

表示层模式:Dispatcher View—分发者视图模式

阅读更多

Context
System controls flow of execution and access to presentation processing, which is
responsible for generating dynamic content.
Note
The Dispatcher View pattern, like the Service to Worker pattern, describes a common
combination of other patterns from the catalog. Both of these macro patterns describe the
combination of a controller and dispatcher with views and helpers. While describing this
common structure, they emphasize related but different usage patterns.
Problem
The problem is a combination of the problems solved by the Front Controller and
View Helper patterns in the presentation tier. There is no centralized component for
managing access control, content retrieval or view management, and there is duplicate
control code scattered throughout various views. Additionally, business logic and
presentation formatting logic are intermingled within these views, making the system less
flexible, less reusable, and generally less resilient to change.
Intermingling business logic with view processing also reduces modularity and
provides a poor separation of roles among Web production and software development
teams.
Forces
Authentication and authorization checks are completed per request.
Scriptlet code within views should be minimized.
Business logic should be encapsulated in components other than the view.
Control flow is relatively simple and is typically based on values encapsulated with
the request.
View management logic is limited in complexity.
Solution
Combine a controller and dispatcher with views and helpers (see "Front Controller"
on page 172 and "View Helper" on page 186) to handle client requests and prepare a
dynamic presentation as the response. Controllers do not delegate content retrieval to
helpers, because these activities are deferred to the time of view processing. A dispatcher is
responsible for view management and navigation and can be encapsulated either within a
controller, a view, or a separate component.
Dispatcher View describes the combination of the Front Controller and View Helper
patterns with a dispatcher component. While this pattern and the Service to Worker pattern
describe a similar structure, the two patterns suggest a different division of labor among the
components. The controller and the dispatcher typically have limited responsibilities, as
compared to the Service to Worker pattern, since the upfront processing and view
management logic are basic. Furthermore, if centralized control of the underlying resources
is considered unnecessary, then the controller is removed and the dispatcher may be moved
into a view.
Since the Service to Worker and Dispatcher View patterns represent a common
combination of other patterns from the catalog, each warrants its own name to promote
efficient communication among developers. Unlike the Service to Worker pattern, the
Dispatcher View pattern suggests deferring content retrieval to the time of view processing.
In the Dispatcher View pattern, the dispatcher typically plays a limited to moderate
role in view management. In the Service to Worker pattern, the dispatcher typically plays a
moderate to large role in view management.
A limited role for the dispatcher occurs when no outside resources are utilized in
order to choose the view. The information encapsulated in the request is sufficient to
determine the view to dispatch the request. For example:
http://some.server.com/servlet/Controller?next=login.jsp
The sole responsibility of the dispatcher component in this case is to dispatch to the
view login.jsp.
An example of the dispatcher playing a moderate role is the case where the client
submits a request directly to a controller with a query parameter that describes an action to
be completed:
http://some.server.com/servlet/Controller?action=login
The responsibility of the dispatcher component here is to translate the logical name
login into the resource name of an appropriate view, such as login.jsp, and dispatch to that
view. To accomplish this translation, the dispatcher may access resources such as an XML
configuration file that specifies the appropriate view to display.
On the other hand, in the Service to Worker pattern, the dispatcher might be more
sophisticated. The dispatcher may invoke a business service to determine the appropriate
view to display.
The shared structure of these two patterns, as mentioned above, consists of a
controller working with a dispatcher, views, and helpers.

分享到:
评论

相关推荐

    J2EE Patterns

    - **调度视图**(Dispatcher View):负责分发视图更新。 #### 业务层模式 - **业务代理**(Business Delegate):简化远程业务对象的调用。 - **服务定位器**(Service Locator):查找并管理服务实例。 - **会话...

    强大安全多线程的Flux模式

    这意味着数据从服务器获取,经过Action Creator,然后通过Dispatcher分发到Store,最后Store更新视图。这种设计避免了传统MVC模式中复杂的双向绑定问题,减少了状态同步的复杂性。 1. **Action Creators**:是触发...

    SpringMVC.zip

    它将Web应用的处理逻辑与表示层分开,提供了松散耦合和模块化的开发方式,使得开发者可以专注于业务逻辑,而无需过多关注底层细节。 2. **MVC模式**:在MVC模式中,Model代表数据模型,View负责显示数据,...

    spring mvc入门

    MVC设计模式主要包括三个核心组件:Model(模型),View(视图),和Controller(控制器)。在Spring MVC中,这些组件的职责分别如下: - Model(模型):主要用于封装数据和业务逻辑,可以使用JavaBean来表示模型...

    简单的java入门springmvc可执行demo

    6. **View**:表示层组件,如JSP、FreeMarker等,负责展示模型数据。 7. **@RequestMapping**:用于映射HTTP请求的方法,可以根据URL、方法类型、参数等进行映射。 8. **@PathVariable**:用于从URL模板中提取变量...

    struts2源代码

    Struts2是一个基于MVC(Model-View-Controller)设计模式的开源Java Web框架,它在Web应用开发中被广泛使用。源代码是理解任何软件系统核心运作方式的关键,对于初学者来说,深入研究Struts2的源代码可以帮助他们更...

    学软件编程需必学的英语)第二学年Java方向

    2. **Dispatcher调度员**:分发用户请求至合适的控制器。 3. **Result结果**:控制器处理请求后返回的结果。 4. **Space空间**:这里可能指服务器端的空间资源。 5. **Interceptor拦截器**:类似过滤器,但更加灵活...

    discuz源码分析

    接着,我们关注`Dispatcher`类,它是请求分发器,根据URL中的信息,找到对应的模块、操作和方法,然后调用相应的控制器。这个过程涉及URL解析、路由规则和控制器实例化。 在控制器层面,Discuz! 使用了类来表示不同...

    s2sh struts2 struts1 原理部分详细讲解及流程图

    其主要特点是通过ActionServlet作为控制器,实现了请求分发,并通过ActionForm处理业务逻辑,同时使用JSP作为视图层展示结果。 1. **请求分发**:当用户发起HTTP请求时,Struts1的FilterDispatcher(或后来的...

    flux-webpack-boilerplate

    在 Flux 中,数据从服务器流入 Store,然后通过 Actions 和 Dispatcher 分发到 View 层进行渲染。这种设计确保了状态的一致性和可预测性,避免了常见的 MVC(模型-视图-控制器)模式中的复杂性问题。 1. **Actions*...

    springmvc搭建

    在本教程中提供的源码可能包含了配置文件(如`web.xml`、`dispatcher-servlet.xml`)、控制器类、服务层接口及实现、以及测试用例等。说明文档可能详细解释了每个部分的作用以及如何配置和运行项目。 总之,Spring ...

    《jgroup in action》

    JGroups通过一系列构建模块来实现其功能,这些构建模块包括了传输层(Transport Layer)、消息分发器(Message Dispatcher)等。这些构建模块共同作用于消息的处理与传递过程。 #### 1.3 The Protocol Stack 协议栈在...

Global site tag (gtag.js) - Google Analytics