Closed cterse closed 5 years ago
Not going with inheritance between DTOs and Entities. Look at this Stack Overflow answer about whether DTOs should use inhertance or composition.
DTOs, at least in this application, provide a layer between the interface and the entity objects. So that if there are certain changes in the entities which does not reflect on the front end, then that change would be made in the entity class itself without changing the DTO which reflects the front end.
For e.g., suppose in our application we are extracting Aadhar Numbers from our DB and show it on the front end. If someday, we choose to not source Aadhar nos. from our DB and instead source it from the Government API, logically, this change is only in the entity class and not on the front end. DTO, which forms a layer between the front end and the entities, prove useful in such scenarios.
Also, the mappings between the DTOs and entities should be updated in such cases.
DTOs serve as a layer between the client and entities that are stored in the DB. Entities are almost always a superset of DTOs, so it makes sense to
extend
the enitites from the DTOs. Research the architecture to reduce code redundancy like writing getters and setters in both DTOs and entities.