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
11
votes
4 answers

Data Transfer Object DTO Where to build

Trying to refactor some code. I see some classes creating DTO objects which are being passes in the service layer and returned later by the @RestController. As I know it is best to build the Data Transfer Objects only in the controllers and pass…
strash
  • 1,291
  • 2
  • 15
  • 29
11
votes
4 answers

Framework for converting java objects

I am working on project that converts database entities into DTO objects. To do it a special converter class is used for each convertion. I am providing simplified example of the things we are doing. I intentionally missed setters/getters and some…
Zalivaka
  • 763
  • 2
  • 13
  • 20
11
votes
4 answers

Should I implement DTOs in repository pattern with EF?

In my project I'm using EF Code First approach. I have a repository layer, service layer and presentation layer (ASP.NET MVC). I'm using a dedicated viewmodel for each view. What I'm confused about is that should my services return entities to the…
11
votes
2 answers

Grails: Can I use domain objects when I don't want to save anything?

Some of my domain classes are getting rather rich: They implement an interesting comparable, might have plus, minus, multiply and div, many have some convenient getters which call services and determine complicated things. And most of all, they…
Mikey
  • 4,692
  • 10
  • 45
  • 73
10
votes
2 answers

How to Design Data Transfer Objects in Business Logic Layer

DTO I'm building a Web application I would like to scale to many users. Also, I need to expose functionality to trusted third parties via Web Services. I'm using LLBLGen to generate the data access layer (using SQL Server 2008). The goal is to build…
JustAProgrammer
  • 589
  • 2
  • 8
  • 17
10
votes
3 answers

Set Current TimeZone to @JsonFormat timezone value

@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd-MM-yyyy", timezone = "Asia/Kolkata") private Date activationDate; From the above java code, I want to set timezone value as Current System timezone using…
10
votes
3 answers

Transaction Boundary and DTO conversion with JPA

I have been wondering how this anomaly should be handled: DTO's should be converted in the controller, the service layer does not need to know about them. Transaction boundaries are defined by the service layer. But how do you avoid a JPA…
Juru
  • 1,623
  • 17
  • 43
10
votes
2 answers

Please explain the Repository-, Mapping-, and Business-Layer relations and responsibilities

I've been reading a lot about this stuff and I am currently in the middle of the development of a larger web-application and its corresponding back-end. However, I've started with a design where I ask a Repository to fetch data from the database…
Stefan Falk
  • 23,898
  • 50
  • 191
  • 378
10
votes
3 answers

MVC architecture DTO/Model mapping/conversion

Using Spring MVC we normally see Controller, Service and Repository layer. The Repository layer uses Entity model which is one to one mapping with database. I thought of following - Should Service layer use the same Entity model? Should Service…
Bhushan Bhangale
  • 10,921
  • 5
  • 43
  • 71
10
votes
2 answers

Tracking changes in complex object graph

I started to think about tracking changes in complex object graph in disconnected application. I have already found several solutions but I would like to know if there is any best practice or what solution do you use and why? I passed same question…
Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
10
votes
3 answers

Getting a Page of DTO objects from Spring Data repository

I'm trying to use DTOs in a Spring project to decouple business and presentation but I'm having problems while retrieving data from the Spring Data repository. Here I have a sample code: public Page findAll(int pageIndex) { return…
David Moreno García
  • 4,423
  • 8
  • 49
  • 82
10
votes
4 answers

Data Trasfer Objects Between Layers in Domain Driven Design

Domain layers are communicating the other layers via Data Transfer Objects(DTOs). I confused about DTOs. DTO 1 is between Domain and Presentation Layer. DTO 2 is between Domain and Data Layer. Should I create two different DTO objects between…
barteloma
  • 6,403
  • 14
  • 79
  • 173
10
votes
3 answers

Optimistic locking in a RESTful application

At work, we're developing a RESTful application where the data layer will be handled by Hibernate. But we're not sure how to handle updates on entities. We're planning to do the following: 1) client requests an entity by id 2) Hibernate loads the…
user2054927
  • 969
  • 1
  • 12
  • 30
10
votes
2 answers

To use or not to use Data transfer objects(DTO) in a Web Api Chat Application Backend Server

I have a chat application backend built using Web Api where I am exposing several database entities directly to clients. I was wondering whether there is any positive points to map the entities to DTOs or should I continue exposing the entities as I…
Lamin Sanneh
  • 310
  • 5
  • 16
10
votes
4 answers

What is the best practice to deal with navigation properties when using DTO and POCO objects?

I'm trying to wrap my head around Domain Driven Development. I want to make sure I have a good foundation and understanding of it, so it would be great if recommendations to use AutoMapper or similar are avoided here. My architecture currently…
David Anderson
  • 13,558
  • 5
  • 50
  • 76