Coupling and cohesion — the dual metrics of good design
Fast recall
Quick revision
Core answer
Interview-ready guide
Interview answer
Cohesion and coupling describe two different views of a design. Cohesion asks whether a module's internal responsibilities belong together. Coupling asks how much the module relies on contracts and details outside itself.
The usual target is high cohesion and controlled coupling, but I do not treat it as a mathematical formula. For example, a focused payment adapter can be cohesive while still coupled to a provider protocol. Extracting responsibilities from a God Class may improve cohesion but introduce more messages and coordination. I evaluate both: keep one invariant together, give each module a clear purpose, and make cross-module contracts explicit and stable.
Coupling and cohesion — the dual metrics of good design
Direct Answer
Cohesion describes how closely responsibilities inside a module belong together; coupling describes how strongly that module relies on others. High cohesion and controlled coupling often support maintainability, but they are separate qualities: a focused class may still depend on many systems, and splitting code can sometimes increase coupling.
Code Example
// Focused responsibility: pricing an order.
final class OrderPricer {
private final TaxCalculator tax;
OrderPricer(TaxCalculator tax) {
this.tax = tax;
}
Money total(Money subtotal, Address address) {
return subtotal.add(tax.calculate(subtotal, address));
}
}
OrderPricer can be cohesive because its work is about pricing. Its coupling still depends on the size and stability of TaxCalculator, Money, and Address. An interface keyword alone does not settle that second question.
Common Mistakes & Pitfalls
- Using a formula: high cohesion does not automatically create low coupling.
- Assuming every split helps both: extraction can add messages, DTOs, ordering rules, or network dependencies.
- Calling every interface loose coupling: a broad or unstable interface can remain tightly coupled.
- Splitting by line count: ten tiny classes can scatter one invariant and increase coordination.
- Ignoring operational coupling: shared databases, timing, retries, and deployment order may matter more than Java imports.
Check your understanding
Answer these without looking back at the article.
- What is a God class and how does it violate both metrics?
- How do SOLID principles help achieve high cohesion and low coupling?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.