tags:

views:

47

answers:

1

More and more applications need different representations of similar objects, e.g., when crossing the wire with web services or when mapping to the database. When you are working with a domain model you probably need one kind of objects in your business layer/domain model (small, lots of behaviour) and another when crossing process or network boundaries (big, only data) or when talking to the database (e.g., LINQ to SQL only supports 1-to-1 mapping between DB tables and generated/mapped objects).

This means you have to write a lot of code performing the rote task of translating/mapping similar objects to eachother. Surely there must be some kind of framework or tool to help you do this? Or is manual coding the only way to really be in control? We have investigated using reflection and XML/attribute mapping to solve this ourselves but it quickly gets fairly complicated, e.g., mapping subobjects and lists or several primitives on one object to a subobject on the other object.

We are using C# on .NET 3.5.

A: 

If the scenario permits it, you should always code against interfaces and abstractions, not against concrete classes. That way you can have a dedicated class/set of classes that deal with transforming one kind of objects into another - something along the lines of the Adapter pattern, for example. Maybe you could try and tweak your design in that direction.
And yes, I think manual coding is the only way to really be in control.

Boyan