Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between Transfer objects and Domain objects

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..

like image 946
copenndthagen Avatar asked Jul 18 '11 11:07

copenndthagen


People also ask

What is the difference between DTO and domain object?

If using anemic data model (i.e. your domain objects don't have any logic), DTO and domain object can be the same object. No. Domain objects have no specific relation to any persistence. In simple words, they are parts to ensure the business logic required to run the application.

What is difference between model and DTO?

Data Transfer Objects (DTOs) and View Models (VMs) are not the same concept! The main difference is that while VMs can encapsulate behaviour, DTOs do not. The purpose of a DTO is the transfer of data from one part of an application to another.

What is a domain object?

"a domain object is a logical container of purely domain information, usually represents a logical entity in the problem domain space ... In general, domain objects should know how to. recognize which [of their] references indicate aggregation and which ones indicate association. copy themselves.

What is difference between Dao and DTO in Java?

DAO is a class that usually has the CRUD operations like save, update, delete. DTO is just an object that holds data. It is JavaBean with instance variables and setter and getters. The DTO is used to expose several values in a bean like fashion.


2 Answers

  • 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

like image 52
Bozho Avatar answered Sep 20 '22 17:09

Bozho


A Data-Transfer-Object (DTO) is used to exchange data between different parts of an application (such as different layers), or different applications.

  • DTO's are simply a "dumb" data structure.
  • They are used in contracts / interface definitions - this means that any component that uses one of these interfaces "knows" about these objects.

Domain Objects (DO) (and the classes from which they are derived) implement business logic, as such they are only located in the Business logic layer / Domain (the essential meaning is the same even if the terms are different).

Because DO's implement business logic they can be complex, and can include methods, events and so on.

One more point about DTOs

According to the Martin Fowler school of thought a DTO is a combination of several objects (each of which would be what most people would commonly call a DTO); the rationale is that in situations it's less expensive to send larger packages of data less frequently (as opposed to being "chatty" and sending many small packages constantly across the wire).

So where most people would view a DTO as a single object Martin F is saying a DTO is simply an "envelop" that contains several discrete (and possibly unrelated) objects. Not a big issue IMO - most people take the view that a DTO is as per my definition at the top of this answer (or something close to it).

like image 33
Adrian K Avatar answered Sep 23 '22 17:09

Adrian K