Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • 12
    I can not tell you what should you do, but to my experience working with DTO, inheritance and composition sooner than later hunt you like a bad coffee. I will never reuse DTO again. Ever. Plus I don't consider similar DTOs to be a DRY violation. Two endpoints that return the same representation can reuse the very same DTOs. Two endpoints that return similar representations are not returning the same DTOs so I make specific DTOs for each. If I were forced to choose, the composition is the less problematic in the long run. Commented Jul 17, 2017 at 14:44
  • @Laiv this is the correct answer to the question, just don't. Not sure why you put it as a comment Commented Jul 17, 2017 at 15:23
  • 3
    @Laiv: What do you use instead? In my experience, people who struggle with this are simply overthinking it. A DTO is just a container for data, and that's all it is. Commented Jul 17, 2017 at 15:26
  • 1
    TheCatWhisperer because my arguments would be mainly opinion based. I'm still trying to address this kind of problems in my projects. @RobertHarvey true, don't know why I tend to see things harder than they really are. I'm still working on the solution. I was quite convinced that HAL was the model meant to solve these problems, but reading your answer I realised that I do my DTO too granulars too. So I will put in practice your approach first. The changes are going to be less dramatic than shifting completely to HATEOAS. Commented Jul 17, 2017 at 17:58
  • Try this for a good discussion that might help you: stackoverflow.com/questions/6297322/… Commented Jul 17, 2017 at 20:11