Questions tagged [dto]

DTO is an acronym for Data Transfer Object, a design pattern used in data transfer.

DTO is an acronym for Data Transfer Object, a design pattern used in transferring data through internal or external interfaces. A DTO protects the application's internal data by acting as dummy storages, the whole logic is implemented only in actual Domain Objects (DO).

Pros:

  • Fewer remote calls (typically one, getDto() vs. individual getId(), getName(), etc.)
  • Improved data capsulation (Remote systems need only to know the details of the DTO, not DO internals)

Cons:

  • class explosion
  • conversions needed between DTOs and DOs
2100 questions
677
votes
8 answers

Difference between DTO, VO, POJO, JavaBeans?

Have seen some similar questions: What is the difference between a JavaBean and a POJO? What is the Difference Between POJO (Plain Old Java Object) and DTO (Data Transfer Object)? Can you also please tell me the contexts in which they are used? Or…
jai
  • 21,519
  • 31
  • 89
  • 120
436
votes
10 answers

Plain Old CLR Object vs Data Transfer Object

POCO = Plain Old CLR (or better: Class) Object DTO = Data Transfer Object In this post there is a difference, but frankly most of the blogs I read describe POCO in the way DTO is defined: DTOs are simple data containers used for moving data between…
Patrick Peters
  • 9,456
  • 7
  • 57
  • 106
394
votes
12 answers

What is a Data Transfer Object (DTO)?

In MVC are the model classes DTO? If not, what are the differences and do we need both?
249
votes
9 answers

any tool for java object to object mapping?

I am trying to convert DO to DTO using java and looking for automated tool before start writing my own. I just wanted to know if there any free tool available for the same.
ravinikam
  • 3,666
  • 6
  • 28
  • 25
207
votes
4 answers

REST API - DTOs or not?

I am currently creating a REST-API for a project and have been reading article upon article about best practices. Many seem to be against DTOs and simply just expose the domain model, while others seem to think DTOs (or User Models or whatever you…
benbjo
  • 2,382
  • 3
  • 18
  • 21
154
votes
11 answers

Why are data transfer objects (DTOs) an anti-pattern?

I've recently overheard people saying that data transfer objects (DTOs) are an anti-pattern. Why? What are the alternatives?
ntownsend
  • 7,462
  • 9
  • 38
  • 35
132
votes
9 answers

DTO = ViewModel?

I'm using NHibernate to persist my domain objects. To keep things simple I'm using an ASP.NET MVC project as both my presentation layer, and my service layer. I want to return my domain objects in XML from my controller classes. After reading some…
autonomatt
  • 4,393
  • 4
  • 27
  • 36
112
votes
7 answers

What is the difference between an MVC Model object, a domain object and a DTO

What is the difference between a MVC Model object, a domain object and a DTO? My understanding is: MVC Model object: Models the data to be displayed by a corresponding view. It may not map directly to a domain object, i.e. may include data from one…
Timothy Mowlem
  • 1,121
  • 2
  • 8
  • 3
99
votes
11 answers

Best Practices For Mapping DTO to Domain Object?

I've seen a lot of questions related to mapping DTOs to Domain Objects, but I didn't feel they answered my question. I've used many methods before and have my own opinions but I'm looking for something a little more concrete. The Situation: We…
Brian Ellis
  • 1,829
  • 1
  • 19
  • 24
93
votes
4 answers

Difference between Entity and DTO

What is the difference between a DTO and an Entity? In details these are my questions: What fields should the DTOs have? For example my entity classes are: @Entity public class MyFirstEntity implements Serializable { @Id @GeneratedValue …
Display Name
  • 1,121
  • 2
  • 11
  • 14
81
votes
5 answers

DDD - which layer DTO should be implemented

I am learning about DDD so apologies if my question is naive. I think I need to use Local Data Transfer Object in order to display data to the users as a lot of properties are not part of any of Entity / Value Objects. However, I am not sure where…
user2105030
  • 831
  • 1
  • 7
  • 7
59
votes
3 answers

Reusing DTO for various request/response types vs explicitness of what is required / what should be returned

I started wondering on whether I am not falling into an antipattern here, so please advise on the best practices. I am designing a REST API with a set of various endpoints and I wanted to wrap the request & response parameters into nice DTO. For…
Bartosz
  • 4,406
  • 7
  • 41
  • 80
53
votes
9 answers

DTO or Domain Model Object in the View Layer?

I know this is probably an age-old question, but what is the better practice? Using a domain model object throughout all layers of your application, and even binding values directly to them on the JSP (I'm using JSF). Or convert a domain model…
sma
  • 9,449
  • 8
  • 51
  • 80
50
votes
2 answers

DTO naming conventions , modeling and inheritance

We are building a web app using AngularJS , C# , ASP.Net Web API and Fluent NHibernate. We have decided to use DTOs to transfer data to the presentation layer ( angular views). I had a few doubts regarding the general structuring and naming of…
Sennin
  • 1,001
  • 2
  • 10
  • 17
48
votes
2 answers

Should the repository layer return data-transfer-objects (DTO)?

I have a repository layer that is responsible for my data-access, which is called by a service layer. The service layer returns DTOs which are serialized and sent over the wire. More often than not, services do little more than access a repository…
JulianR
  • 545
  • 1
  • 4
  • 7
1
2 3
99 100