Transfer Object Pattern is used to transfer data with multiple attributes from the client to the server at one time. Transfer objects are also called numeric objects. The transport object is a simple POJO class with a getter/setter method that is serializable so it can be transmitted over the network. It does not have any behavior. The server-side business class typically reads data from the database, populates the POJO, and sends it to the client or passes it by value. For the client, the transport object is read-only. The client can create its own transport object and pass it to the server to update the values in the database at once. The following are the entities of this design pattern.
- Business Object - A business service that populates data for transport objects.
- Transfer Object - Simple POJO, only the method of setting/getting properties.
- Client - The client can send a request or send a transport object to a business object.
Create a transfer object.
Create a business object.
Use StudentBO to demonstrate the transfer object design pattern.
Executing the program, outputting results:
Student: [RollNo : 0, Name : Robert ] Student: [RollNo : 1, Name : John ] Student: Roll No 0, updated in the database Student: [RollNo : 0, Name : Michael ]