Is there a good way to automate the translation of objects between different architectural layers?
More and more applications require different representations of such objects, for example, when crossing wires with web services or when mapping to a database. When working with a domain model, you probably need one kind of entity in your business layer / domain model (small, many behavior) and another when crossing processes or network boundaries (big, data only) or when talking to a database (for example LINQ to SQL only supports 1-to-1 mapping between DB tables and generated / mapped objects).
This means that you have to write a lot of rote code to translate / map similar objects to each other. Surely there are some frameworks or tools to help you do this? Or is hand coding the only way to really control? We've explored using reflection and XML / attribute mapping to work this out for ourselves, but it quickly becomes quite complex, such as mapping subobjects and lists or multiple primitives on one object to a subobject on another object.
We are using C # on .NET 3.5.
If your script allows it, you should always code interfaces and abstractions, not concrete classes. This way you can have a dedicated class / set of classes that deal with converting one type of object to another - something like adapter strings, for example. Perhaps you can try and tweak your design in this direction.
And yes, I believe hand coding is the only way to really control.
source to share