Tuesday, August 26, 2008

Intention revealing interfaces

In the argument of "Intention revealing interfaces" vs "Reusable DTO/message" i will 99% of the time lean heavily toward the "Intention revealing interfaces" side.

I have just encountered code where i can see a (somewhat) noble intention of trying to keep the number of messages available in an assembly down to a minimum. Considering the system(s) mainly passes entities across boundaries, message are not common currency.
Unfortunately i don't think enough thought was put into the decision. Leaving the notion of passing entities around as another issue, the fact that this DTO is now being used as a request AND response object in MULTIPLE service functions means the intention of each DTO is very unclear.
There are multiple fields on the DTO that are not used by the service and there is a magical "ObjectPacket" property that is of type object (as in System.Object) that is actually quite important. The reason the property's type was left as object is because of "reuse", as the different functions do different things with that property.
OMG.
Many hours, nay days, of bug fixing could have been saved if this DTO was split in to just 4 classes, 2 response and 2 requests. These could have been generic enough for the remained of the functions and revealed, along with the service function names* the intention of the call.

Thinks of other when you names stuff (classes, components, service, methods and parameters) and think of whether re usability is actually a benefit before bundling on bonus properties to a transfer object. ;)

*yes this is a JBOS interaction

No comments: