Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is using DTO's and Entities breach of DRY principle?

I was looking at a library called Automapper. I am having a few concerns with this:

  1. We dont want to expose our data model (GOOD). Why should the datamodel closely resemble your DB?

  2. using lightweight DTOs instead of your entities. (GOOD)

  3. Now I need to map my entities to these DTOs. Am i respecting the DRY principle??

like image 863
Perpetualcoder Avatar asked Oct 14 '22 09:10

Perpetualcoder


1 Answers

One could argue that DTOs violate DRY, but if it makes sense for your situation then I wouldn't think twice about it.

DRY, like most programming best practices, isn't a silver bullet. Sometimes you have to compromise. In this case, I'd argue that violating DRY is perfectly acceptable in order to prevent issues that can arise from leaking your domain details to callers that don't need it (e.g. N+1 lazy-loading performance issues).

like image 177
Kevin Pang Avatar answered Oct 27 '22 16:10

Kevin Pang