Why use Transfer Objects

Enterprise applications with server side implementation of business logic normally expose some methods for accessing the business components. These methods are call 1…* times by clients to obtain the data that is required by them. These methods, which are normally exposed through remote methods will result in a network overhead.

  • Client applications/portlets normally require data from more than one domain objects or enterprise beans.
  • Client achieves this by making multiple calls to the business components.
  • A lot of chatter over the network degrades network and application performanceperformance.
  • Also the number of read cycles out number the write cycle in majority of applications.
  • On the other hand a enterprise bean may provide more data than needed to a client request.

The solution to this problem is to have a single method call to the server side implementation of the business compoents to extract the required data. This can be done by making a serialized Transfer Object from 1…* domain objects. Transfer Object is constructed on demand by the enterprise bean and returned to the remote client.  

When the client makes a single remote method invocation to the enterprise bean to request the Transfer Object, the enterprise bean then constructs a new Transfer Object instance, copies required values into the object and returns it to the client. The client receives the Transfer Object and uses accessor methods on the Transfer Object to get data from the Transfer Object.

The same transfer object can be used to transfer data back to the business layer in a single remote invocation. 



public class WorkTO implements java.io.Serializable {
  	public String workID; // can be private. wil have to provide getter
         // setter
  	public String days;
  	public String workdays;
  	public String payLevel; // Transfer Object constructors...


 // for Hibernate Simple POJO
 public class Work {
  Long id;
  private String workID;
  private String days;

  	public WorkTO getWorkTO()
   		WorkTO to = new WorkTO();
   		to.workdays = new WorkDays().getWorkDays();//some other Entity bean implementation
   		to.payLevel = new PayLevel().getPayLevels();
   		return to;


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s