Questions tagged [dto]

Data Transfer Objects are for moving data between processes.

Data Transfer Objects are for moving data between processes.

They just allow for storage, retrieval, and (de-)serialization of data. Any other behavior would make them.

91 questions
179
votes
6 answers

What is the point of using DTO (Data Transfer Objects)?

What is the point of using DTO and is it an out dated concept? I use POJOs in the view layer to transfer and persist data. Can these POJOs be considered as an alternative to DTOs?
Vinoth Kumar C M
  • 15,455
  • 23
  • 57
  • 86
53
votes
4 answers

Ways to share DTO across microservices?

My scenario is as follows. I am designing a system designed to receive data from various types of sensors, and convert and then persist it to be used by various front-end and analytics services later. I'm trying to design every service to be as…
49
votes
1 answer

What is the use of DTO instead of Entity?

I am working on RCP application, I'm new to this application. Spring beans are used to write business logic to save/fetch entities. But, instead of sending entities directly to client we are converting to DTOs and populating client. While saving, we…
Naveen Kocherla
  • 613
  • 1
  • 6
  • 5
25
votes
2 answers

Clean Architecture: What is the View Model?

In his book 'Clean Architecture', Uncle Bob says that the Presenter should put the data that it receives into something he calls the 'View Model'. Is this the same thing as the 'ViewModel' from the Model-View-ViewModel (MVVM) design pattern or is…
Fearnbuster
  • 401
  • 1
  • 4
  • 11
20
votes
2 answers

What data should a repository return

I have a simple project where the controller calls the service, and the service calls the repository in order to get the needed data. Assuming that we have these domain models: // this model has a RepositoryA built for it Class A { public string…
Uentee
  • 391
  • 2
  • 4
  • 9
19
votes
5 answers

Sharing DTO objects between microservices

TL;DR - Is it ok to share a POJO library between services? Generally we like to keep the sharing between services strictly limited to none if possible. There has been some debate whether or not the service that is sharing data should provide a…
Aerith
  • 301
  • 1
  • 2
  • 5
18
votes
4 answers

Use composition and inheritance for DTOs

We have a ASP.NET Web API that provides a REST API for our Single Page Application. We use DTOs/POCOs to pass data through this API. The problem is now, that these DTOs are getting bigger over time, so now we want to refactor the DTOs. I am looking…
officer
  • 299
  • 1
  • 2
  • 6
13
votes
1 answer

Which C# type should one prefer for defining lists in DTOs?

I was wondering if there is a recommended approach to defining a property of a plain object that is used for data transfer, for example via a REST-API which is a list of other objects. Which C# type should one prefer for defining those? List
AyCe
  • 378
  • 1
  • 3
  • 13
12
votes
4 answers

C# - Initialize DTOs in constructor or via properties?

Update: C# 9 should fix this problem using records :D I was wondering if there is a recommended approach to initializing the properties of a plain object that is used for data transfer, for example via a REST-API. Here are two variants I can think…
AyCe
  • 378
  • 1
  • 3
  • 13
11
votes
7 answers

Is separating most classes into data field only class and method only classes (if possible) a good or an anti-pattern?

For example, a class usually have class members and methods, eg: public class Cat{ private String name; private int weight; private Image image; public void printInfo(){ …
ocomfd
  • 5,652
  • 8
  • 29
  • 37
10
votes
3 answers

Is it anti-pattern to have inheritence in a dto?

Are data transfer objects or POJOs meant to be final or can they be extended and create hierarchies for them? It is not clear to me if such a value class is properly designed only as a final class and what are some good examples/designs of a…
Jim
  • 317
  • 1
  • 3
  • 10
9
votes
2 answers

Use DTO Pattern or Serialize Domain Objects

A colleague of mine is against using DTOs and rather feels we should just return Entity / Domain objects serialized for a REST api. He feels DTO is an anti pattern and sited this article Data Transfer Object is a Shame. Although the article sited…
greyfox
  • 869
  • 1
  • 8
  • 11
9
votes
1 answer

Data Objects for each layer(DTO vs Entity vs Response objects)

Let's say I'm building a Customer web application(in Spring Boot 2), which also exposes rest end points. I'm modeling my application into 3 layers. a) UI - CustomerDTO b) REST - CustomerRESTResponse/CustomerRESTRequest Service - CustomerDTO Data…
Sandeep
  • 103
  • 1
  • 1
  • 5
9
votes
1 answer

Reusing a top-level DTO as a child in another DTO

What is the recommendation regarding re-using DTO's as a child in another DTO? I'm using ASP.NET Web API (C#) and consuming the results with Angular 1.x (not sure if that really matters). I have the following DTOs class SiteDto { public int SiteId…
Adam Plocher
  • 347
  • 3
  • 11
8
votes
2 answers

When is it appropriate to map a DTO back to its Entity counterpart

From what I've read and implemented, DTO is the object that hold a subset of value from a Data model, in most cases these are immutable objects. What about the case where I need to pass either new value or changes back to the database? Should I…
aggietech
  • 1,082
  • 2
  • 11
  • 22
1
2 3 4 5 6 7