clothesLines

This is the third part in my little series about dependency anti-patterns. The first part was about the God Node, the second one about the Bypass

Images and nomenclature are based on Degraph.

When you have two slices with lots of parallel connections as in the image on the side, you found this patterns. Just as with real clotheslines there might be some crossing in the lines, but the majority is parallel.

This kind of stuff happens when you split classes into packages (or larger slices) not by the domain they deal with, but by the pattern they implement. An example would be a set of entities and there matching DAOs. If you put all the entities in one package and all the DAOs in another you get exactly this pattern. It is an example of high coupling and low coehesion and in case you are wondering: Yes we normally strive for the opposite.

You want to avoid clotheslines because the affected nodes are couple so tightly together that you can't really split them, so you might as well throw them in one bag. Which in turn might result in a giant node, you you don't want either.

The good news is the situation is easy to improve. Just arrange the classes connected by clothesline into one package. Possibly on their own, and if they have cross connections with other pairs, together with those. You'll end up with something that looks more like the image below: More dependencies inside a package, fewer between packages. Also known as high cohesion, low coupling.

clothesLinesFixed