Junior — Middle
Do you combine multiple DTOs with the same structures into one common class or object?
sobes.tech AI
Answer from AI
It is worth combining multiple DTOs (Data Transfer Objects) with identical structures into a single common class or object if they truly represent the same entity or concept. This helps avoid code duplication and simplifies maintenance.
However, if DTOs are used in different contexts with different semantics, even with the same structure, it is better to keep them separate to avoid mixing responsibilities and creating confusion.
For example, if you have two DTOs with fields id and name, but one is used for transferring user data, and the other for transferring product data, it is better to create different classes to clearly reflect their purpose.