- What is the right way to create DTOs from business objects?
- Who should be responsible for creating them? BO/DTO itself from BO/some static factory?
- Where should they reside in code if I have, f.e. some core library and a specific service API library that I need DTO for? In core library next to BO(which seems incorrect)/in specific library?
- If I have encapsulated fields in my BO how do DTO grab them? (obviously in case when BO is not responsible for creating DTOs)
As an example assume that I have some Person BO like this:
class Person
{
private int age;
public bool isBigEnough => age > 10;
}
I want age to be an internal state of Person but still I need to communicate my BO to some api. Or having private field in my class that I want to send somewhere already means that it should be public?
- Are there any general considerations of how to use DTOs alongside business classes with encapsulated data?
Aucun commentaire:
Enregistrer un commentaire