Data Transfer Object (DTO) Pattern
🔹 What is DTO (Data Transfer Object)?
A DTO is a simple Java class used to transfer data between different layers, such as from the database to the service layer or controller.
It only carries data and does not contain any business logic.
🔹 Why use DTO?
✅ Security: DTO helps hide unnecessary fields (e.g., passwords).
✅ Performance: Sends only required data, reducing memory usage.
✅ Loose Coupling: Changes in the database entity do not affect DTO.
✅ Customized API Response: Only sends the fields that the client needs.
This follows the DTO pattern, ensuring data transfer between Entity and Dto, which is a good practice.
1️⃣ Dto comes as input.
2️⃣ Dto is converted into a Entity.
3️⃣ Entity is saved in the database.
4️⃣ Entity is converted back into Dto.
5️⃣ The Dto is returned.
Comments
Post a Comment