`

表示层模式: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.

分享到:
评论

相关推荐

    关于设计模式MVC(Model View Controller)模型-视图-控制器

     模型-视图-控制器(MVC)是Xerox PARC在八十年代为编程语言Smalltalk-80发明的一种软件设计模式,至今已被广泛使用。最近几年被推荐为Sun公司J2EE平台的设计模式,并且受到越来越多的使用 ColdFusion 和 PHP 的...

    敏捷软件开发:原则、模式与实践

    第25章 ABSTRACT SERVER模式、ADAPTER模式和BRIDGE模式 第26章 PROXY模式和STAIRWAY TO HEAVEN模式:管理第三方API 第27章 案例研究:气象站 第六部分 ETS案例研究 第28章 VISITOR模式 第29章 STATE模式 第30章 ETS...

    快速学习C++设计模式:观察者模式实例代码

    观察者模式是目前应用最广、影响范围最大的模式之一,因为 Observer 的一个实例 MVC结构(Model/View/Control )在系统开发架构设计中有着很重要的地位和意义,实现了业务逻辑和表示层的解耦。下面示例代码以篮球...

    JavaEE设计模式之表示层模式

    因为表示层是请求驱动的,所以“用户”可以是任意请求的发起者。控制器处理该请求。模型就是业务数据,而视图就是最终发生的应答。控制器是与请求发生联系的起点。控制器就是一个主管,首先规划要做哪些更新和要显示...

    23种设计模式入门到精通详解.txt

    单例模式:某个类只能有一个实例,提供一个全局的...责任链模式:将请求的发送者和接收者解耦,使的多个对象都有处理这个请求的机会。 迭代器模式:一种遍历访问聚合对象中各个元素的方法,不暴露该对象的内部结构。

    Java EE设计模式:Spring企业级开发最佳实践

    在 Spring 中,观察者模式广泛应用于事件驱动编程中,例如,在 Spring MVC 中,使用观察者模式来处理请求和响应。 4.MVC Pattern:模型视图控制器模式,分离应用程序的关注点,实现高内聚、低耦合的设计。 在 ...

    Python 程序语言设计模式思路-结构型模式:组合模式:将对象组合成树形结构

    组合模式作为一种强大的设计模式,通过将对象组合成树形结构,可以表示“部分-整体”的层次结构,并统一地处理单个对象和组合对象,简化了客户端代码的复杂性,从而提高代码的灵活性和可扩展性。在实际开发中,它在...

    AndroidArchitectureComponent:具有Room数据库,视图模型和实时数据的Android体系结构组件

    该应用程序为表示层使用Model-View-ViewModel(MVVM)架构。 每个片段对应一个MVVM视图。 View和ViewModel使用LiveData和以下设计原则进行通信: ViewModel对象没有对活动,片段或Android视图的引用。 这会导致...

    c++ 建造者模式实例

    建造者模式: 将一个复杂对象的构建与它的表示分离,使得同样的构建过程可以创建不同的表现。这就是建造者模式。 建造者模式可以把一个产品的内部表象与产品的生成过程分隔开来,从而可以使一个建造过程就可以生成...

    浅析23种软件设计模式

    15. 解释器模式:解释器模式的主要思想是给定一个语言后,可以定义出其文法的一种表示,并同时提供一个解释器。这种模式的优点是可以使客户端使用这个解释器来解释这个语言中的句子,但缺点是增加了系统的复杂度。 ...

    GoF 的 23 种设计模式

    迭代器(Iterator)模式:提供一种方法来顺序访问聚合对象中的一系列数据,而不暴露聚合对象的内部表示。 访问者(Visitor)模式:在不改变集合元素的前提下,为一个集合中的每个元素提供多种访问方式,即每个元素...

    工厂模式三层结构示例项目源码

    CodematicDemoF3 是一个基于工厂模式的三层架构示例项目源码,基于VS2005 SP1开发(如果没有装SP1,web项目会打不开),结构更简洁,提供更多有效的示例源码参考。方便用户更好的理解和使用该架构进行开发,配合动软...

    表示层设计模式:InterceptingFilter(截取筛选器)

    本页内容上下文问题影响因素解决方案变体示例结果上下文相关模式致谢 上下文对于任何一个曾经从头建立Web应用程序的人来说,他们都会有这样的体会:这项任务所需要的独立完成的工作量要比建立内部客户端-服务器应用...

    网站生成器-工厂模式开发,用于页面表示层

    网站开发的一层 二层开发完成之后,所有的页面表示层都可以用此软件来生成。这是我们开发时自己开发的软件。绝对好用。提高工作效率。

    软件设计模式实验2结构型模式源码

    3.装饰者模式:这是一个关于相亲的故事。某家有女初长成,七大姑八大姨欲帮忙寻得佳婿,后在各种群、圈、网站,收集了各种男人的资料。这里需要一个应用程序生成收集过来的男人的描述,如..........4.组合模式:用...

    表示层设计模式:在ASP.NET中实现PageController

    本页内容上下文实现策略测试考虑事项结果上下文相关模式 上下文您要在ASP.NET中构建Web应用程序,您希望通过使用内置的PageController(页面控制器)来利用ASP.NET的事件驱动特性。返回页首 实现策略默认情况下,...

    《XML》实验任务书 XML Schema 答案 解答

    2、严格按照下图给出的文档模型,在XML Schema编辑环境的Schema视图中完成book.xsd的编写(不要使用Text视图进行编写): 在上图中,没有指定简单类型元素和属性的数据类型,请根据合理的情况,完成数据类型的创建...

Global site tag (gtag.js) - Google Analytics