`

表示层模式: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种设计模式(C++).pdf

    - Interpreter模式:给定一个语言,定义它的文法的一种表示,并定义一个解释器,这个解释器使用该表示来解释语言中的句子。 在实际开发中,设计模式的使用可以帮助开发人员避免重新发明轮子,同时也能够为团队提供...

    设计模式可复用面向对象软件的基础 源代码

    解释器模式(Interpreter)提供了一种方式来表示语言的语法和语义;策略模式(Strategy)定义了一系列算法,并使它们可以相互替换,使算法的变化独立于使用它的客户。 3. **创建型设计模式**:这类模式关注对象的...

    C# 23种设计模式(中文高清带书签)

    - 迭代器模式:提供一种方法顺序访问聚合对象的元素,而又不暴露其底层表示。 - 中介者模式:定义一个中介对象来简化原本复杂的交互关系。 - 备忘录模式:在不破坏封装性的前提下,捕获一个对象的内部状态,并在...

    设计模式 23种设计模式PPT

    - 生成器模式:将复杂对象的构建与其表示分离,使得同样的构建过程可以创建不同的表示。 2. 结构型模式: - 适配器模式:允许两个不兼容的接口协同工作。 - 组合模式:将对象组合成树形结构,以表示部分-整体的...

    33种JAVA设计模式DEMO

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

    Head First设计模式(完整高清版).pdf

    - 迭代器模式:提供一种方法顺序访问聚合对象的元素,而又不暴露其底层表示。 - 状态模式:允许对象在其内部状态改变时改变它的行为。 - 策略模式:定义一系列算法,并将每个算法封装起来,使它们可以互相替换。 ...

    JAVA 设计模式手册

    - 迭代器模式:提供一种方法顺序访问聚合对象的元素,而又不暴露其底层表示。 - 观察者模式:定义对象间的一种一对多的依赖关系,当一个对象的状态发生改变时,所有依赖于它的对象都会得到通知并自动更新。 - ...

    23种设计模式.pdf

    4. 建造者模式:将一个复杂对象的构建与其表示分离,使得同样的构建过程可以创建不同的表示。 5. 原型模式:通过复制已有对象来创建新对象,避免反复创建相同类型的对象。 结构型模式关注如何组合和结构化对象,...

    【Java设计模式-源码】组合模式:构建灵活的树结构

    在Java中,组合模式用于将对象组合成树结构,以表示部分 - 整体层次结构。该模式允许客户端统一对待单个对象和对象的组合。 二、组合设计模式的别名 Object Tree(对象树) Composite Structure(组合结构) 三、...

    设计模式ppt

    - 迭代器模式:提供一种方法顺序访问聚合对象的元素,而又不暴露其底层表示。 - 中介者模式:用一个中介对象来封装一系列的对象交互,降低耦合度。 - 备忘录模式:在不破坏封装性的前提下,捕获对象的内部状态并...

    objectC 编程之道 设计模式解析 书+源码

    本书涵盖了单例模式、工厂模式、观察者模式、代理模式、装饰器模式、策略模式、状态模式、模版方法模式、建造者模式、适配器模式、桥接模式、组合模式、享元模式、迭代器模式、职责链模式等经典设计模式。...

    Gof设计模式

    - 迭代器模式:提供一种方法顺序访问聚合对象的元素,而又不暴露其底层表示。 - 中介者模式:定义一个中介对象来简化原本复杂的对象间交互。 - 备忘录模式:在不破坏封装性的前提下,捕获一个对象的内部状态,并...

    设计模式PPT---25种设计模式详解

    5. 对象池模式(Object Pool):通过对象池管理对象的生命周期,避免频繁创建和销毁对象的开销。 结构型模式关注如何组合对象和类,包括: 1. 适配器模式(Adapter):将两个不兼容的接口转换为兼容的接口。 2. ...

    【Java设计模式-源码】数据映射器模式:解耦数据存储与业务逻辑

    数据映射器是一个数据访问层,它在持久数据存储(通常是关系数据库)和内存数据表示(领域层)之间执行双向数据传输。该模式的目标是使内存表示和持久数据存储相互独立,并且数据映射器本身也相互独立。当需要在领域...

    PHP设计模式源码

    - 迭代器模式:提供一种方法来顺序访问聚合对象的元素,而不暴露其底层表示。 - 状态模式:允许对象在其内部状态改变时改变它的行为,对象看起来似乎修改了它的类。 - 策略模式:定义一系列算法,并将每个算法...

    C++设计模式大总结

    - 迭代器模式:提供一种方法顺序访问一个聚合对象的元素,而又不暴露其底层表示。 - 状态模式:允许对象在内部状态改变时改变它的行为,对象看起来好像改变了它的类。 - 策略模式:定义一系列的算法,并将每一个...

    设计模式课程设计---使用5个以上不同的设计模式完成(java)

    5. **建造者模式(Builder Pattern)**:建造者模式将复杂对象的构建与其表示分离,使得同样的构建过程可以创建不同的表示。在Java中,我们可以定义一个建造者类,逐步构建产品对象,然后通过Director类来指导建造过程...

    【Java 设计模式-源码】Business Delegate 模式:简化业务服务交互

    通过使用该模式,我们可以实现层与层之间的松散耦合,并封装关于如何定位、连接和与构成应用程序的业务对象进行交互的知识。 四、Business Delegate 模式的详细解释及实际示例 实际示例: 在使用 Java EE 的企业应用...

    Design_Patterns-Elements_of_Reusable_Object-Oriented_Software

    ### 设计模式——可复用面向对象软件的基础元素 #### 一、概述 《设计模式:可复用面向对象软件的基础元素》是一本被广泛誉为面向对象编程领域经典之作的书籍,它由Erich Gamma、Richard Helm、Ralph Johnson 和 ...

Global site tag (gtag.js) - Google Analytics