05 — Package & Component Principles¶
Driving question: What makes a component boundary stable as a system evolves?
Learning objectives¶
- Explain release/reuse/common-closure/common-reuse principles.
- Use dependency cycles and stability to discuss component structure.
- Identify inappropriate “layer” dependencies.
- Relate component boundaries to ownership and deployment constraints.
Principles of cohesion¶
- Release/Reuse Equivalence: reusable things need a coherent versioned release boundary.
- Common Closure: group elements that tend to change for the same reasons.
- Common Reuse: avoid forcing clients to depend on things they do not use.
These principles pull in different directions; package design is a trade-off.
Principles of coupling¶
Acyclic dependency structures reduce coordinated release pressure. Stable dependencies should point toward components that change less frequently or contain higher-level policy.
Define instability for a component as:
\[
I = \frac{C_e}{C_a + C_e}
\]
where \(C_e\) is efferent coupling and \(C_a\) is afferent coupling. The number is useful only when interpreted with system context.
Design / research exercise¶
Build the package dependency graph of a medium-size project. Identify cycles, highly unstable hubs, and “utility” packages. Propose one boundary change and predict its impact on build/test/release coupling.
Suggested reading¶
- Robert C. Martin, component cohesion and coupling principles.