Sambuddha
Sambuddha

Reputation: 245

Value Object vs Data Transfer Object

I was a part of one of the project where we were producing java webservice and publishing into server. Some other java application was consuming the web service through extjs.

In that producer application was following Domain Driven Design. We were using two types of pojos , Domain Objects and DTO objects. Both the classes were having same properties variables. And DTO class was implementing Serializable class.

First we were creating the domians objects from db call and then converting the domains objects into dtos and published in websevice.

Now what i want to know is this a good practice to have these two types of objects ? Why the dtos were implementing serialzable( one reason could be to maintain the state of the objects while webservice call through network --- this reason i found in net, but not clear to me ) ?

Any link to this or expert's explanation is welcome.

Thanks in Advance.

Upvotes: 3

Views: 4010

Answers (1)

Michael Laffargue
Michael Laffargue

Reputation: 10304

Objects are made Serializable to be able to be transferred. It allows to convert Object to bytes and then bytes to Object.

Note that usually DTO are made lighter (since travelling to client) than your Domain Objects that usually have a lot of attributes made for Business processing only.

So basically in a multi-layer project you can have for example :

  • Domain Objects mapped to the database
  • A Business Layer that will process Business Rules
  • A transformation from Domain Objects to DTOs
  • DTOs are transferred to the client

Some reading:

http://www.oracle.com/technetwork/java/transferobject-139757.html

https://softwareengineering.stackexchange.com/questions/171457/what-is-the-point-of-using-dto-data-transfer-objects

Difference between DTO, VO, POJO, JavaBeans?

Upvotes: 3

Related Questions