Stable Dependencies Principle
Definition
Depend in the direction of stability.
A component that we expect to be volatile should not be depended on by a component that is difficult to change. Otherwise, the volatile component will be difficult to change.
Most of this comes from Clean Architecture - Chapter 14: Component Coupling.
Stability metrics
One way of measuring the stability of a component is to count the number of dependencies that enter and leave that component. These counts allow us to calculate the positional stability of that component.
- Fan-in - incoming dependencies. This metric identifies the number of classes outside this component that depend on classes within the component.
- Fan-out - outgoing dependencies. This metric identifies the number of classes inside this component that depend on classes outside the component.
- Instability (
I) -I = Fan out / (Fan in + Fan out). This metric has the range[0, 1].I = 0indicates a maximally stable component.I = 1indicates a maximally unstable component.
Excerpts from Clean Architecture
It is the perversity of software that a module that you have designed to be easy to change can be made difficult to change by someone else who simply hangs a dependency on it. Not a line of source code in your module will suddenly become more challenging to change.