• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

general question: generic mapping of different object types

 
Christian Schlaefcke
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Folks,

I have a datasource where I get a lot of different objects with a special kind of outline, lets say general data objects (DO). In my business logic I have business object (BO) representations of that DO�s, that carry the same information but in more simple bean like style. Because I don�t want to have DO�s in my business logic part of the application I need a mapping mechanism to convert DO�s to BO�s.

Are there any techniques/patterns available to have the mapping from DO to BO and way round in generic style? I want to prevent writing hundrets of mapper classes by hand. Reflection is also a no go (performance). The attribute names and the getter and setter methods could be totally different between DO�s and representing BO�s.

Any hint would be helpful!

Thanks & Regards,

Chris
 
Zeeshan Samdani
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Chris,

Why don�t you try using JDO for this purpose.

JDO separates the data mapping and storage impl from the objects, without requiring you to implement separate business/ data objects.
If you need to, you can implement a Data Access service layer to provide a point of control for retrieve/ store/ query etc operations. This only needs simple passthru methods and queries, yet will provide the abstraction you need in case of changing storage mechanisms. You can even replace with JDBC implementation if needed.

eg:

DataService
- retrieve (Object key)
- store (Object inst)
- delete (Object inst)
- queryByName (String name)

CustomerService extends DataService
- queryByAddress(�)
- etc

Anyway you definitely want to avoid writing all those implementations by hand. Using a tool will handle your hundreds of classes in hours instead of months

Zeeshan Samdani
www.powermapjdo.com
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you have effectively two Value Objects in your architecture? What do you gain by populating one object type in your data access layer (your DOs) and converting them to BOs for your business layer? Is there something peculuar about your requirements?


Reflection is also a no go (performance).

I wouldn't discount Reflection for that reason. It performs far better than many people suggest. And I'd imagine converting from your DOs to BOs is probably a bigger performace hit anyway.
 
Zeeshan Samdani
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Paul says, there�s no need for two sets of objects.

Many people want to keep a degree of separation, but this is much better achieved by routing thru a single Data Access Service control point rather than separate entity implementations.

Zeeshan Samdani
www.powermapjdo.com
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic