`

表示层模式:Transfer Object Assembler—传输对象组装器模式

阅读更多

Context
In a Java 2 Platform, Enterprise Edition (J2EE) application, the server-side business
components are implemented using session beans, entity beans, DAOs, and so forth.
Application clients frequently need to access data that is composed from multiple objects.
Problem
Application clients typically require the data for the model or parts of the model to
present to the user or to use for an intermediate processing step before providing some
service. The application model is an abstraction of the business data and business logic
implemented on the server side as business components. A model may be expressed as a
collection of objects put together in a structured manner (tree or graph). In a J2EE
application, the model is a distributed collection of objects such as session beans, entity
beans, or DAOs and other objects. For a client to obtain the data for the model, such as to
display to the user or to perform some processing, it must access individually each
distributed object that defines the model. This approach has several drawbacks:
Because the client must access each distributed component individually, there is a
tight coupling between the client and the distributed components of the model over the
network
The client accesses the distributed components via the network layer, and this can
lead to performance degradation if the model is complex with numerous distributed
components. Network and client performance degradation occur when a number of
distributed business components implement the application model and the client directly
interacts with these components to obtain model data from that component. Each such
access results in a remote method call that introduces network overhead and increases the
chattiness between the client and the business tier.
The client must reconstruct the model after obtaining the model's parts from the
distributed components. The client therefore needs to have the necessary business logic to
construct the model. If the model construction is complex and numerous objects are
involved in its definition, then there may be an additional performance overhead on the
client due to the construction process. In addition, the client must contain the business logic
to manage the relationships between the components, which results in a more complex,
larger client. When the client constructs the application model, the construction happens on
the client side. Complex model construction can result in a significant performance
overhead on the client side for clients with limited resources.
Because the client is tightly coupled to the model, changes to the model require
changes to the client. Furthermore, if there are different types of clients, it is more difficult
to manage the changes across all client types. When there is tight coupling between the
client and model implementation, which occurs when the client has direct knowledge of the
model and manages the business component relationships, then changes to the model
necessitate changes to the client. There is the further problem of code duplication for model
access, which occurs when an application has many types of clients. This duplication makes
client (code) management difficult when the model changes.
Forces
Separation of business logic is required between the client and the server-side
components.
Because the model consists of distributed components, access to each component is
associated with a network overhead. It is desirable to minimize the number of remote
method calls over the network.
The client typically needs only to obtain the model to present it to the user. If the
client must interact with multiple components to construct the model on the fly, the
chattiness between the client and the application increases. Such chattiness may reduce the
network performance.
Even if the client wants to perform an update, it usually updates only certain parts of
the model and not the entire model.
Clients do not need to be aware of the intricacies and dependencies in the model
implementation. It is desirable to have loose coupling between the clients and the business
components that implement the application model.
Clients do not otherwise need to have the additional business logic required to
construct the model from various business components.
Solution
Use a Transfer Object Assembler to build the required model or submodel. The
Transfer Object Assembler uses Transfer Objects to retrieve data from various business
objects and other objects that define the model or part of the model.
The Transfer Object Assember constructs a composite Transfer Object that represents
data from different business components. The Transfer Object caries the data for the model
to the client in a single method call. Since the model data can be complex, it is
recommended that this Transfer Object be immutable. That is, the client obtains such
Transfer Objects with the sole purpose of using them for presentation and processing in a
read-only manner. Clients are not allowed to make changes to the Transfer Objects.
When the client needs the model data, and if the model is represented by a single
coarse-grained component (such as a Composite Entity), then the process of obtaining the
model data is simple. The client simply requests the coarse-grained component for its
composite Transfer Object. However, most real-world applications have a model composed
of a combination of many coarse-grained and fine-grained components. In this case, the
client must interact with numerous such business components to obtain all the data
necessary to represent the model. The immediate drawbacks of this approach can be seen in
that the clients become tightly coupled to the model implementation (model elements) and
that the clients tend to make numerous remote method invocations to obtain the data from
each individual component.
In some cases, a single coarse-grained component provides the model or parts of the
model as a single Transfer Object (simple or composite). However, when multiple
components represent the model, a single Transfer Object (simple or composite) may not
represent the entire model. To represent the model, it is necessary to obtain Transfer Objects
from various components and assemble them into a new composite Transfer Object. The
server, not the client, should perform such "on-the-fly" construction of the model.

分享到:
评论

相关推荐

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

    单例模式:某个类只能有一个实例,提供一个全局的访问点。 简单工厂:一个工厂类根据传入的参量决定创建出那一种产品类的实例。...迭代器模式:一种遍历访问聚合对象中各个元素的方法,不暴露该对象的内部结构。

    33种JAVA设计模式DEMO

    创建型模式 这些设计模式提供了一种在创建对象的同时隐藏创建逻辑的方式,而不是使用 new 运算符直接实例化对象。这使得程序在判断针对某个给定实例需要创建哪些对象时更加...传输对象模式(Transfer Object Pattern)

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

    第一部分 敏捷开发 第1章 敏捷联盟 第2章 极限编程概述 第3章 计划 第4章 测试 第5章 重构 第6章 一次编程实践 ...附录B UML表示法II:统计多路复用器 附录C 两上公司的讽刺小品 附录D 源代码就是设计 索引

    GoF 的 23 种设计模式

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

    data-transfer-object:一个简单的数据传输对象

    数据传输对象 此类旨在使添加和查看数据变得容易。 加载对象、数组或json; 使用对象、数组或点符号读取; 输出到json字符串。 用法 您可以使用数组、可数组对象或 json 字符串实例化该类。 这些都是等价的: $ ...

    12种常用设计模式C#代码示例

    10,迭代器模式:提供一种方法,顺序访问一个聚合对象中的各个元素,而又不暴露其内部的表示。 11,组合模式:允许你将对象组合成树形结构来表现“整体/部分”层次结构。组合能让客户以一致的方式处理个别对象已经...

    接口描述-表示层-控制层-数据调度器-数据层1

    表示层Browse:浏览本地文件导入:将选择的文件传输至控制层开始转换:触发控制层中的translation控制层Home:展示主页面import_backgr

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

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

    c++ 建造者模式实例

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

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

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

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

    第Ⅰ部分 敏捷开发 第一章 敏捷实践 1.1 敏捷联盟 1.2 原则 1.3 结论 参考文献 第二章 极限编程概述 2.1 极限编程实践 ...附录B UML表示法Ⅱ:统计多路复用器 附录C 两个公司的讽刺小品 附录D 源代码就是设计 索引

    JavaEE设计模式之表示层模式

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

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

    中文名: 敏捷软件开发:原则、模式与实践 原名: Agile Software Development:Principles,Patterns and Practices ...附录B UML表示法II:统计多路复用器 附录C 两上公司的讽刺小品 附录D 源代码就是设计 索引

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

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

    c++设计模式-行为型模式-解释器模式

    解释器(Interpreter)模式的定义:给分析对象定义一个语言,并定义该语言的文法表示,再设计一个解析器来解释语言中的句子。也就是说,用编译语言的方式来分析应用中的实例。这种模式实现了文法表达式处理的接口,...

    WD计算机网络最新PPT.rar

    第四层:传输层(TransportLayer)功能:网络决策实现分组和重新组装 第五层:会话层(SessionLayer)功能:通信同步错误恢复和事务操作 第六层:表示层(PresentationLayer)功能:转换数据格式、数据加密、解密 第七...

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

    享元模式:在天猫商城里存在着成天上万的网店,但是天猫所提供的网站模板是一样的,存在许多天猫网店使用同一个网店模板的情况,如果每一个网店都用一个网店对象来表示,因为网店数量巨大,我们需求很

    充电桩欧标DIN70121 协议分析(layer2,layer3) (中文精简版)

    充电桩欧标DIN70121 协议分析(layer2,layer3),主要包括: 1:layer2:数据链路层 2:layer3:网络层 3:layer4: 传输层 4:layer5:传输协议 5:layer6:表示层 6:layer7:应用层

    嵌入式与实时系统开发:使用UML对象技术框架与模式.part2.

    本书结合嵌入式系统编程中最新概念,使用统一建模语言以及来自于对象技术中的最佳实践,揭示了实时系统开发过程中复杂问题和细节问题,阐明了可调度性,行为模式,实时框架等重要主题,以期帮助读者成为更加有效的...

Global site tag (gtag.js) - Google Analytics