815143 wrote:I create DTOs as one set. Most of the time the set is inclusive enough that it can be used as is in all the layers.
I am sure every one of you would have come across this type of code. We copy objects from Domain to application layer or from Data layer to business layer.
They are mere copy and if the DO's , BO's are long, we ahve to write so many methods like convertToDomain object etc. I am wondering if there is a pattern that we could apply to handle this generically.Why can't they be in the same group?
One of the thing I am thinking of is to use reflection to copy object of similar type. For eg. PersonDO might have age, name and DOB, and PersonBO might have just name and DOB.
Would it not be a good idea to copy over from PersonDO to PersonBO provided all variables match using reflection.Code generation. Create the DTOs. Create the copy code (presuming it is actually needed.)
It might sound dumb. But I don't like the various copy that we do, it literally fills up the java file.The reason certainly sounds odd. But so does the need to copy from one DTO to another.