What not to do – ‘bundle’ unrelated components together’
So – here’s another real-world they shouldn’t have done this –really! item; somewhat related to my previous post about projects, but a different slant -
MyP had used pipeline components fairly extensively, a very good idea in my view, especially in this case.
But, as discussed in that previous post all pipeline components, regardless of where they were used, were bundled together in a single assembly.
To make matters worse, a single pipeline component often served more than one purpose, for more than one client.
So – for example – a pipeline initially created to remove an unwanted trailer from a message from a particular sender, ended up also converting the message to xml, and then extended to support another format, from another sender, only that the two don’t share any code – the execute method of the pipeline component has a switch statement on the sender name, and runs two separate functions.
Now – considering all the components are in the same assembly already, how can this make matters worse?
Well – single responsibility principle is one that I generally like – I’m a new developer working on this project, I see a component called TrailerRemover, used in a pipeline called <someSender>_Receive I assume this is processing messages from <someSender> and that it removes a trailer.
I eventually discover it does a lot more, and processes messages from another sender as well.
One of the side effects of this is time wasting – it is much more difficult, in my experience, to maintain systems that don’t follow the single responsibility principle.
This is aggrevated by the fact that this is usually a symptom, if not a cause, for bad architecture – I shouldn’t be able to mix logic for two different senders, not unless specified common logic is factored out and reused properly, from a shared assembly.
Now when I come to change some code I find it difficult to know what the impact may be – where exactly is this thing used?