J2EE Design Pattern : Business Tier Patterns : Transfer Object Design Pattern
Transfer Object Design Pattern? |
Transfer Object transfers multiple data elements over tiers.
Problem
J2EE applications implement server-side business components, some of their methods return back data to the client. These components are typically implemented as remote objects, such as session beans and entity beans. When these business components expose fine-grained get and set methods, a client must invoke several getter methods to get all the attribute values it needs, which are remote calls. Such remote calls create a network overhead. Even when not accessing remote components, you still need to access components that are encapsulated in a different tier.
Context
To transfer multiple data elements over a tier.
Solution
- Use a Transfer Object to carry multiple data elements across a tier.
- A Transfer Object is designed to optimize data transfer across tiers. Instead of sending or receiving individual data elements, a Transfer Object contains all the data elements in a single structure required by the request or response.
- The Transfer Object is passed by value to the client. Therefore all calls to the Transfer Object are made on copies of the original Transfer Object.
Participants and Collaborations
Client
The Client needs to access a Component to send and receive data. Typically, the Client is a Component in another tier. For example, a Component in the presentation tier can act as a client of some business-tier components.
Component
The Component can be any component in another tier that the client accesses to send and receive data. The Component can be in the presentation tier (PresComponent), business tier (BizComponent) or integration tier (IntComponent).
PresComponent
The PresComponent is a component in the presentation tier, such as a helper object, an instance of a BusinessDelegate, a command object, and so on.
BizComponent
The BizComponent is a component in the business tier, such as a Business Object, Application Service Service Facade, and so on.
IntComponent
The IntComponent is a component in the integration tier, such as a Data Access Object.
TransferObject
The TransferObject is a serializable plain old Java object that contains several members to aggregate and carry all the data in a single method call.
Implementation Strategies
- Updatable Transfer Objects
- Multiple Transfer Objects
- Entity Inherits Transfer Object Strategy
Example for Transfer Object |
Recent Comments