๐ Coupling and Cohesion¶
Two big design qualities:
- Coupling: how strongly one part depends on another.
- Cohesion: how well the responsibilities inside a part belong together.
Great designs aim for low coupling and high cohesion.
โ Low Coupling¶
Low coupling means components can change independently.
Signs of high coupling:
- Many imports and cross-calls between modules
- One small change forces changes in many places
- Code canโt be reused without dragging dependencies along
โ High Cohesion¶
High cohesion means a module/class/function does one focused job.
Signs of low cohesion:
- โUtilityโ modules that contain unrelated helpers
- Classes with many unrelated methods
- Functions that do validation + parsing + storage + formatting
โ Example: Improve Cohesion¶
Before (mixed responsibilities):
After (clear responsibilities):
๐ Key Takeaways¶
- Low coupling reduces โblast radiusโ of change.
- High cohesion makes code easier to locate and reason about.
- SoC often improves both coupling and cohesion.