Pergunta

What is the difference between a Response Object and DTO in software architecture? Say I want to get a list of Products in a catalog.

If ProductDTO is this, how is a Product Response class different? Is a Product Response typically just a wrapper on DTO with datetime, error log, or guid, or what is the prime difference? Would like to hear architectural difference between the two.

public class ProductDto
{
    public int ProductId { get; set;},
    public string ProductName { get; set;},
    public string ProductDescription { get; set;},
    public float SalesAmount { get; set;}
}

Resources below do not have specific answer to question,

https://stackoverflow.com/questions/44349199/reusing-dto-for-various-request-response-types-vs-explicitness-of-what-is-requir

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

Note: Question is rejected on Stackoverflow (its more architectural question), so posting here.

Foi útil?

Solução

The DTO is just data related to the object, in this case a product.

A response could contain more information other than the just the productDTO. The response could be an aggregate of multiple DTOs. It also could contain META information like an ID or other type of information. Maybe it will return a success/fail code or other business information

<Response>
 <OtherData/>
 <ProductDto/>
</Response>

It's really just a wrapper for the productDTO. The response could just contain the product as well and no other information.

Outras dicas

Generally, we use DTO for the purpose of user interaction with the database. While we use a response object as a response of the API.

HttpResponse is a response code for API which is used for database operation while DTOs are used as a view model in the application.

Licenciado em: CC-BY-SA com atribuição
scroll top