What is high cohesion and loose coupling and why do they matter?
**Cohesion** measures how strongly related the responsibilities inside a single module or class are. High cohesion means everything in the unit works toward one clear purpose. A class that handles user authentication and also formats PDF reports has low cohesion — its responsibilities are unrelated. High cohesion makes units easier to understand, test, and reuse because there is a single axis of change.
**Coupling** measures how much one module depends on the internal details of another. Tight coupling means a change in module A forces changes in module B. Loose coupling means modules interact only through stable, narrow interfaces — they know what the other module does, not how it does it.
The two principles are complementary: high cohesion pushes related behavior together, loose coupling pushes unrelated modules apart. Together they minimize the blast radius of change.
**Practical forms of coupling to reduce:** - **Data coupling**: pass only the data a function needs, not entire objects - **Control coupling**: don't pass flags that change internal behavior — split into two functions - **Content coupling**: never access another module's private state directly - **Common coupling**: avoid shared global mutable state
**Techniques for loose coupling:** - Depend on interfaces/abstract classes rather than concrete implementations (Dependency Inversion) - Inject dependencies rather than instantiating them internally - Use events or message queues to decouple producers from consumers - Define clear module boundaries with versioned contracts (APIs)
In a microservices context, a service with high cohesion owns one business domain end-to-end. Loose coupling means services communicate over APIs, not shared databases. A change to the Order service's database schema should not require the Inventory service to be redeployed.
The interview signal: candidates who can cite a real refactoring — 'we extracted a notification module because it was tangled with billing' — demonstrate they have lived the tradeoff, not just memorized the definition.
Defines both terms correctly with examples and explains why they complement each other.
Names specific coupling types, explains dependency inversion as a coupling-reduction technique, and gives a concrete real-world example.
Reading the answer is step one. Explaining it unprompted — under interview pressure — is what actually matters. Get AI-graded feedback on your answer with follow-up probes on your weak points.
Get Graded — Free Assessment