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.
- 浏览: 15867 次
- 性别:
- 来自: 北京
-
文章分类
最新评论
发表评论
-
集成层模式:Service Activator—服务激发器模式
2014-04-09 20:31 1146ContextEnterprise beans and o ... -
集成层模式:Data Access Object—数据访问对象模式
2014-04-09 20:31 546ContextAccess to data varies ... -
业务层模式:Service Locator—服务定位器模式
2014-04-09 20:31 1191ContextService lookup and cre ... -
表示层模式:Value List Handler—值列表处理器模式
2014-04-09 20:32 789ContextThe client requires a ... -
业务层模式:Composite Entity—复合实体模式
2014-04-08 21:38 524ContextEntity beans are not i ... -
业务层模式:Session Facade—会话门面模式
2014-04-08 21:38 437ContextEnterprise beans encap ... -
业务层模式:Transfer Object—传输对象模式
2014-04-08 21:37 457ContextApplication clients ne ... -
业务层模式:Business Delegate—业务委托模式
2014-04-08 21:37 1007ContextA multi-tiered, distri ... -
表示层模式:Dispatcher View—分发者视图模式
2014-04-08 21:37 557ContextSystem controls flow o ... -
表示层模式:Service to Worker—工作者服务模式
2014-04-07 10:48 1011ContextThe system controls flow ... -
表示层模式:Front Controller—前端控制器模式
2014-04-07 10:45 397ContextThe presentation-tier re ... -
表示层模式:Composite View—复合视图模式
2014-04-07 10:41 500ContextSophisticated Web page ... -
表示层模式:View Helper—视图助手模式
2014-04-07 10:37 1052ContextThe system creates pre ... -
表示层模式:Intercepting Filter—拦截过滤器模式
2014-04-07 10:29 638Context The presentati ...
相关推荐
不同的对象等价和个体实例方法也在书中有所涉及,如使用singleton类、策略模式、内部case语句、参数化方法以及解释器实现等。 8. 库存与事务:库存与事务涉及到管理库存和处理事务的基本方法。书中讨论了事务的类型...
- Interpreter模式:给定一个语言,定义它的文法的一种表示,并定义一个解释器,这个解释器使用该表示来解释语言中的句子。 在实际开发中,设计模式的使用可以帮助开发人员避免重新发明轮子,同时也能够为团队提供...
解释器模式(Interpreter)提供了一种方式来表示语言的语法和语义;策略模式(Strategy)定义了一系列算法,并使它们可以相互替换,使算法的变化独立于使用它的客户。 3. **创建型设计模式**:这类模式关注对象的...
- 迭代器模式:提供一种方法顺序访问聚合对象的元素,而又不暴露其底层表示。 - 中介者模式:定义一个中介对象来简化原本复杂的交互关系。 - 备忘录模式:在不破坏封装性的前提下,捕获一个对象的内部状态,并在...
- 生成器模式:将复杂对象的构建与其表示分离,使得同样的构建过程可以创建不同的表示。 2. 结构型模式: - 适配器模式:允许两个不兼容的接口协同工作。 - 组合模式:将对象组合成树形结构,以表示部分-整体的...
创建型模式 这些设计模式提供了一种在创建对象的同时隐藏创建逻辑的方式,而不是使用 new 运算符直接实例化对象。这使得程序在判断针对某个给定实例需要创建哪些对象时更加...传输对象模式(Transfer Object Pattern)
- 迭代器模式:提供一种方法顺序访问聚合对象的元素,而又不暴露其底层表示。 - 状态模式:允许对象在其内部状态改变时改变它的行为。 - 策略模式:定义一系列算法,并将每个算法封装起来,使它们可以互相替换。 ...
- 迭代器模式:提供一种方法顺序访问聚合对象的元素,而又不暴露其底层表示。 - 观察者模式:定义对象间的一种一对多的依赖关系,当一个对象的状态发生改变时,所有依赖于它的对象都会得到通知并自动更新。 - ...
16. 迭代器模式:提供一种方法顺序访问聚合对象的元素,而不暴露其底层表示。 17. 中介者模式:定义一个中介对象来简化原本复杂的对象间交互。 18. 备忘录模式:在不破坏封装性的前提下,捕获一个对象的内部状态,并...
在Java中,组合模式用于将对象组合成树结构,以表示部分 - 整体层次结构。该模式允许客户端统一对待单个对象和对象的组合。 二、组合设计模式的别名 Object Tree(对象树) Composite Structure(组合结构) 三、...
面向对象编程(Object-Oriented Programming,简称OOP)是一种编程范式,它将程序设计中的实体抽象为对象,通过对象之间的交互实现功能。在深度学习的模型搭建和训练过程中,我们可以看到许多OOP设计模式的应用。...
- 迭代器模式:提供一种方法顺序访问聚合对象的元素,而又不暴露其底层表示。 - 中介者模式:用一个中介对象来封装一系列的对象交互,降低耦合度。 - 备忘录模式:在不破坏封装性的前提下,捕获对象的内部状态并...
本书涵盖了单例模式、工厂模式、观察者模式、代理模式、装饰器模式、策略模式、状态模式、模版方法模式、建造者模式、适配器模式、桥接模式、组合模式、享元模式、迭代器模式、职责链模式等经典设计模式。...
16. 迭代器模式:提供一种方法顺序访问聚合对象的元素,而又不暴露其底层表示。 17. 中介者模式:定义一个中介对象来简化原有对象之间的交互关系,降低系统的耦合度。 18. 访问者模式:表示一个作用于某对象结构中...
- 迭代器模式:提供一种方法顺序访问一个聚合对象中的各个元素,而又不暴露其内部的表示。 - 中介者模式:用一个中介对象来封装一系列的对象交互。 - 备忘录模式:在不破坏封装的前提下,捕获一个对象的内部状态,并...
5. 对象池模式(Object Pool):通过对象池管理对象的生命周期,避免频繁创建和销毁对象的开销。 结构型模式关注如何组合对象和类,包括: 1. 适配器模式(Adapter):将两个不兼容的接口转换为兼容的接口。 2. ...
数据映射器是一个数据访问层,它在持久数据存储(通常是关系数据库)和内存数据表示(领域层)之间执行双向数据传输。该模式的目标是使内存表示和持久数据存储相互独立,并且数据映射器本身也相互独立。当需要在领域...
- 迭代器模式:提供一种方法顺序访问聚合对象的元素,而又不暴露其底层表示。 - 中介者模式:定义一个中介对象来简化原有对象之间的交互关系,降低系统的耦合度。 - 状态模式:允许对象在其内部状态改变时改变它...
- 迭代器模式:提供一种方法来顺序访问聚合对象的元素,而不暴露其底层表示。 - 状态模式:允许对象在其内部状态改变时改变它的行为,对象看起来似乎修改了它的类。 - 策略模式:定义一系列算法,并将每个算法...