- 2068 Baishakh (old course) · 5 marks
Short note: cohesion and coupling
Short answer
Cohesion measures how closely elements inside one module belong together; coupling measures interdependence between modules. Good design has high cohesion and low coupling. Best cohesion is functional, best coupling is data; high cohesion usually leads to low coupling.
Write a short note on cohesion and coupling.
Cohesion and coupling are the two main measures of module quality in software design. A good design has high cohesion and low coupling, which makes modules easy to understand, test, change and reuse.
Cohesion
Cohesion is the degree to which the elements inside one module belong together and work toward a single task. Types, from worst (lowest) to best (highest):
- Coincidental – unrelated tasks grouped by chance (e.g. a "utilities" module).
- Logical – tasks of the same category, selected by a flag (e.g. all input routines).
- Temporal – tasks done at the same time (e.g. initialisation).
- Procedural – tasks that follow a fixed order of execution.
- Communicational – tasks that operate on the same data.
- Sequential – output of one task is input to the next.
- Functional – every element contributes to exactly one function (e.g.
computeTax()); the ideal.
Coupling
Coupling is the degree of interdependence between modules. Types, from worst (tightest) to best (loosest):
- Content – one module changes or jumps into the internals of another.
- Common – modules share global data.
- External – modules share an external format, device or protocol.
- Control – one module passes a flag that controls the other's logic.
- Stamp – a whole data structure is passed when only part is needed.
- Data – only the needed simple data items are passed as parameters; the ideal.
| Cohesion | Coupling |
|---|---|
| Inside a single module | Between modules |
| Should be high | Should be low |
| Best type: functional | Best type: data |
| Shows module's focus | Shows module's independence |
High cohesion usually leads to low coupling: when each module does one job, it needs little from other modules.
✓ Answer checked by Claude Sonnet 5.5
Related questions
- Cohesion and coupling in software · Instrumentation II, chapter 9