`

业务层模式:Transfer Object—传输对象模式

阅读更多

Context
Application clients need to exchange data with enterprise beans.
Problem
Java 2 Platform, Enterprise Edition (J2EE) applications implement server-side
business components as session beans and entity beans. Some methods exposed by the
business components return data to the client. Often, the client invokes a business object's
get methods multiple times until it obtains all the attribute values.
Session beans represent the business services and are not shared between users. A
session bean provides coarse-grained service methods when implemented per the Session
Facade pattern.
Entity beans, on the other hand, are multiuser, transactional objects representing
persistent data. An entity bean exposes the values of attributes by providing an accessor
method (also referred to as a getter or get method) for each attribute it wishes to expose.
Every method call made to the business service object, be it an entity bean or a
session bean, is potentially remote. Thus, in an Enterprise JavaBeans (EJB) application such
remote invocations use the network layer regardless of the proximity of the client to the
bean, creating a network overhead. Enterprise bean method calls may permeate the network
layers of the system even if the client and the EJB container holding the entity bean are both
running in the same JVM, OS, or physical machine. Some vendors may implement
mechanisms to reduce this overhead by using a more direct access approach and bypassing
the network.
As the usage of these remote methods increases, application performance can
significantly degrade. Therefore, using multiple calls to get methods that return single
attribute values is inefficient for obtaining data values from an enterprise bean.
Forces
All access to an enterprise bean is performed via remote interfaces to the bean. Every
call to an enterprise bean is potentially a remote method call with network overhead.
Typically, applications have a greater frequency of read transactions than update
transactions. The client requires the data from the business tier for presentation, display, and
other read-only types of processing. The client updates the data in the business tier much
less frequently than it reads the data.
The client usually requires values for more than one attribute or dependent object
from an enterprise bean. Thus, the client may invoke multiple remote calls to obtain the
required data.
The number of calls made by the client to the enterprise bean impacts network
performance. Chattier applications-those with increased traffic between client and server
tiers-often degrade network performance.
Solution
Use a Transfer Object to encapsulate the business data. A single method call is used
to send and retrieve the Transfer Object. When the client requests the enterprise bean for the
business data, the enterprise bean can construct the Transfer Object, populate it with its
attribute values, and pass it by value to the client.
Clients usually require more than one value from an enterprise bean. To reduce the
number of remote calls and to avoid the associated overhead, it is best to use Transfer
Objects to transport the data from the enterprise bean to its client.
When an enterprise bean uses a Transfer Object, the client makes a single remote
method invocation to the enterprise bean to request the Transfer Object instead of numerous
remote method calls to get individual attribute values. The enterprise bean then constructs a
new Transfer Object instance, copies values into the object and returns it to the client. The
client receives the Transfer Object and can then invoke accessor (or getter) methods on the
Transfer Object to get the individual attribute values from the Transfer Object. Or, the
implementation of the Transfer Object may be such that it makes all attributes public.
Because the Transfer Object is passed by value to the client, all calls to the Transfer Object
instance are local calls instead of remote method invocations.

分享到:
评论

相关推荐

    传输对象模式

    **传输对象模式**(Transfer Object Pattern)是一种软件设计模式,主要用于在客户端和服务端之间高效地传输数据。该模式通过使用简单的、可序列化的对象来封装复杂数据结构,使得这些数据能够轻松跨越网络边界进行...

    用Java实现23种设计模式

    用Java实现23种设计模式 1. 创建型模式 工厂模式(Factory Pattern) 抽象工厂模式(Abstract Factory Pattern) ... 传输对象模式(Transfer Object Pattern) 生产者消费者模式(Producer Consumer Pattern)

    33种JAVA设计模式DEMO

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

    20-C-ValueObject-Code.zip

    数据传输对象模式: DTO模式主要用于在系统间或者层与层之间传递大量数据,它是一个无业务逻辑的纯数据容器。DTO的主要目的是减少网络通信开销,避免传输不必要的对象。例如,在Web服务或数据库访问层中,我们可能...

    23种JAVA设计模式和15种J2EE设计模式

    **2.1.3 Transfer Object—传输对象模式** 传输对象模式通过在客户端和服务器端之间传递对象来简化远程调用过程。这些对象通常包含数据和少量的行为,可以有效地减少网络通信开销,并提高系统的性能。 **2.1.4 ...

    《J2EE核心模式》(DAO模式)

    3. **Data Transfer Object (DTO)**:用来在DAO与业务层之间传输数据的简单对象,通常只包含属性,没有业务逻辑。 4. **Client(客户端)**:业务逻辑层的组件,通过调用DAO接口的方法来访问数据,而不直接与数据库...

    设计模式.docx

    #### 传输对象模式(Transfer Object Pattern) 传输对象模式通过在客户端和服务器之间传送轻量级的对象,以减少网络传输的数据量。这种模式适用于需要在分布式环境中高效传输数据的情况。 以上所述的设计模式不仅...

    C#.net8创建webapi,使用SqlSugar,仓储模式,DTO,服务层,控制层的综合应用

    在本文中,我们将深入探讨如何使用C#.NET 8创建一个Web API,同时结合SqlSugar作为ORM工具,以及实现仓储模式、DTO(Data Transfer Object)转换、服务层和服务控制层的架构设计。这个综合应用旨在提供一个高效且可...

    Java设计模式 J2EE设计模式

    GoF设计模式,即Gang of Four设计模式,由《设计模式:可复用面向对象软件的基础》一书中的四位作者提出,包含了23种经典的设计模式。在Java中,这些模式通常体现在面向接口的编程中,例如工厂模式就是其中最常用的...

    J2EE设计模式-PPT(JDON)

    【GoF设计模式】是《设计模式:可复用面向对象软件的基础》一书中提出的23种经典设计模式,它们是面向对象编程中的一种最佳实践集合。在Java中,这些模式主要体现在面向接口编程上,比如工厂模式,它是最常被应用的...

    J2EE Patterns

    - **传输对象组装器**(Transfer Object Assembler):组装传输对象。 - **值列表处理器**(Value List Handler):处理值列表的逻辑。 #### 集成层模式 集成层模式关注于如何将J2EE应用与其他系统或服务进行有效...

    三层架构简化版模板

    - DTO(Data Transfer Object):在不同层之间传输数据的对象,避免了直接暴露业务实体,降低了耦合度。 - UnitOfWork模式:用于管理一组数据库操作,确保它们作为一个单元执行,支持事务处理。 - ORM(Object-...

    mobile.app.ws:使用ObjectDTO的Spring Boot项目

    ObjectDTO是软件设计中常见的一个模式,用于在系统组件之间传递数据,避免了直接暴露业务对象,有助于保持数据层与业务层的解耦。 首先,Spring Boot是一个快速开发框架,它简化了创建独立的、生产级别的基于Spring...

    J2EE 《核心模式》

    7. **Data Transfer Object模式**:用于在不同层之间传输数据,减少网络通信的复杂性。 8. **Singleton模式**:确保一个类只有一个实例,并提供全局访问点。 9. **Decorator模式**:动态地给对象添加新的功能,而...

    web技术架构

    - DTO:数据传输对象,用于在系统组件之间传递数据,不包含业务逻辑。 - BO:业务对象,封装了业务逻辑和操作。 - VO:值对象,主要用来存储显示或交换的数据,不包含任何行为。 了解这些基本概念和技术,可以...

    J2EE设计模式.ppt

    DTO(Data Transfer Object)模式,又称为VO(Value Object)模式,主要用于在J2EE的多层架构间传输数据。DTO就像一个信使,将数据封装在普通的JavaBeans中,避免了直接传输数据库模型或业务对象带来的问题,特别是...

    accp5.0s2在.NET框架下开发三层结构数据库应用系统 上机二代码

    - DTO(Data Transfer Object):用于在不同层次之间传输数据的对象,避免了直接暴露业务对象给外部。 通过实践这些代码,你可以深入理解.NET框架下三层架构的实现,以及如何在实际项目中应用。这将有助于提升你的...

    MVC设计模式

    - **DTO (Data Transfer Object)**:数据传输对象,用于远程调用等过程中传输数据。 通过以上介绍可以看出,MVC设计模式不仅在Web开发中占有举足轻重的地位,也在非Web领域有着广泛的应用。同时,了解POJO和...

    应用分层及规约

    2. **DTO(Data Transfer Object)**:数据传输对象,用于在层与层之间传输数据。 3. **BO(Business Object)**:业务对象,封装了Service层的业务逻辑。 4. **AO(Application Object)**:应用对象,是一种抽象...

Global site tag (gtag.js) - Google Analytics