Transfer Object Pattern in Java
It is used when we want to pass data with multiple attributes in one shot from client to server. Transfer Object is a simple POJO class having getter/setter methods and is serialized so that it can be transferred over the network. Server Side business class normally fetches data from the database and fills the POJO and sends it to the client or passes it by value. For clients, the transfer object is read-only. The client can create its own transfer object and pass it to the server to update values in the database in one shot.
Following are the entities of this type of design pattern:
Transfer Object Simple POJO having methods to set/get attributes only Business Object Fills the Transfer Object with data Client Either requests or sends the Transfer Object to Business Object
- Step 1: Create a Transfer Object
- Step 2: Create a Business Object.
- Step 3: Use the StudentBO to demonstrate Transfer Object Design Pattern
- Step 4: Verify the output.
Step 1: Creating a Transfer Object
Step 2: Creating a Business Object
Step 3: Use the StudentBO to demonstrate Transfer Object Design Pattern
Implementation: List is acting as DB here as shown in demonstrating Transfer Object Design Pattern.
Step 4: Verifying output
Student : [RollNo : 0, Name : Robert ] Student : [RollNo : 1, Name : John ] Student : Roll No 0, updated in the database Student : [RollNo : 0, Name : Michael ]
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.