posted 16 years ago
Hi, what is the best design approach to implement a solution that converts between various objects in different tiers... i.e. domain objects in the business tier, value objects in the data tier, DTOs in the service tier that may have different data representations of the equivalent domain objects etc.
Right now I have seen adapter approaches but this can get kludgy real quick. For instance: DAO returns value object, it gets converted into a business object by some adapter class, it is then again run through a static conversion method in a giant BusinessToServiceObjectAdapter which returns the Service Object. Usually data transformation rules are hardcoded, for instance gender property value "Male" in Business Object may need to be converted to "M" or something similar. Some automation using BeanUtils.copyProperties and such may also be used.
Another approach I have *heard* about is using a domain wide XML representation of data. Now objects in all tiers will know how to represent it's dataset in this XML structure. XSLT will be used for transformation of data using the appropriate XSD. The benefit is maintainability since transformation rules are externalized to the XSD instead of in the code.
What has been your own approach to object conversion?
[ October 22, 2007: Message edited by: Kevin Smither ]