intermediate
High cohesion and low coupling
Keep related behavior close and unrelated modules independent so change impact stays local and dependencies remain understandable.
Cohesion measures how closely module elements belong together—high cohesion means one clear purpose. Coupling measures dependency between modules—low coupling limits change propagation. Aim for modules that are focused internally and loosely connected externally.
Symptoms of low cohesion: unrelated helpers in one file; high coupling: widespread imports when one constant changes.
On interviews: diagnose cohesion/coupling in a sample module graph and suggest one split and one interface.
Common pitfalls: maximizing decoupling into nanomodules, shared global state coupling everything, and confusing package count with design quality.
The trade-off is module granularity—too few god modules versus too many fragmented files.
Checklist:
- Group code that changes together.
- Depend on stable abstractions, not internals.
- Measure impact when touching a module.