Is it okay to create a DTO counterpart of a table in a database assuming its persistent ignorant domain model and the DTO is in the repository?

128 views Asked by At

What prompted me to ask this question is that my class for example Invoice has private fields and i dont want to use its setters because some does calculations of some sort. instead my options are: all fields in constructor or reflection to reconstitute the object from the database (which occurs in the repository layer(repository pattern))

1

There are 1 answers

1
casablanca On

Don't create a separate DTO, just use a good ORM framework. Most modern ORM frameworks (such as Hibernate) can map private fields without needing a getter/setter. Yes, they use reflection internally, but you don't have to write any of that yourself.