Monday, September 29, 2014

Shared Models, Extending

Previously, while working on a logistics system, I encountered a situation where a service and a consumer of the service shared the same class, but within their own domain. Lets say it was a Shipment class for this example. The service returned A.Shipment where a is the namespace and the client used B.Shipment where B is the namespace of the client code. I didn't see it at the time, but what I might have done is to create a shared library that contained the object as a DTO which A and B could use. Each space would then extend or wrap the DTO to add domain specific logic - a decorator pattern could work. Instead I used an explicit cast operator to map the properties from B.Shipment to A.Shipment. This works, but is a clear violation of DRY.

No comments:

Post a Comment