Difference between Transfer objects and Domain objects

copenndthagen picture copenndthagen · Jul 18, 2011 · Viewed 29.1k times · Source

Could you please explain the difference between Transfer objects and Domain objects in simple terms ? And if u could give a Java example, that would be great..

Answer

Bozho picture Bozho · Jul 18, 2011
  • DTOs don't have any logic. They only have fields (state). They are used when transferring data from one layer/subsystem to another
  • Domain objects can have logic (depending on whether you are using domain-driven design or have anemic data model) and they are usually related to the database structure.

If using anemic data model (i.e. your domain objects don't have any logic), DTO and domain object can be the same object.

Related: http://techblog.bozho.net/?p=427