I have the following problem:
A framework generates a class from DB table, each table column is class variable(field).
The generated class has more than 30 fields and just one constructor with no parameters.
To create an instance of that class, I have to use 30 times some setters, which is invitation for inconsistencies.
I cannot use directly constructors with parameters or Builder pattern, as I cannot edit the generated class. What’s the best way to approach this – Wrapper class, thread safe methods, a classic pattern?
I have solved this problem for myself by making a
BeanBuilderclass that uses reflection on the inside. You give it your bean and then call methods likestartBean,valueand similar to fill your bean with data, much like building an XML tree.If you are in love with type safety, you can make a similar class for yourself that works specifically with that bean that you have.