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.