Published May 20, 2020
by Doug Klugh
Managing Complexity
Design your software in such a way that the dependencies between your components do not form a cycle. The resulting component dependency structure will form a Directed Acyclic Graph — such as a tree structure. Draw your component graph as a tree and make sure all the arrows point downward. Then rest assured that your dependencies do not form a cycle.
This Principle of Component Coupling will greatly enhance the structural quality of your software by minimizing coupling and complexity. Coupling increases as the dependencies between modules increase. Not only does high coupling drive up complexity, it geometrically increases the time required for compiling and unit testing. And when you're focused on reducing the execution time within your CI/CD pipeline, high coupling will have a very high cost.
A component is a collection of classes encapsulated within an independently deployable library, such as a jar, gem, or DLL. These libraries are independently deployable when a change to one does not cause others to be recompiled or redeployed. The key to developing independently deployable components is to manage dependencies. For example, changes to an application do not require that framework components be recompiled or redeployed. Applications depend on frameworks. Frameworks do not depend on applications. If developed correctly, you should be able to swap out components during a normal business day, with all users hammering away at your system, with zero downtime.
« Classes are a necessary but insufficient vehicle for decomposition. »
- Grady Booch
Imagine building a large software system out of many small and simple classes. If you only follow the Single Responsibility Principle, this is exactly what you will end up with. So, we need a way to group classes together into larger modules. Components provide a way to encapsulate related classes into larger chunks. The trick is determining which classes should be grouped together within a component — which is resolved by the Principles of Component Cohesion. Then the next challenge is managing the dependencies between components — which is solved by the Principles of Component Coupling.
« It's like building a sandcastle from individual grains of sand. »
- Bob Martin
Stay tuned for more on these Component Design Principles.