Past exam question: Assignment 3, Q24
Open in the Padhaiko appExplain Coupling & Cohesion in detail.
Solution
Modularity Principle (High Cohesion, Low Coupling): In instrumentation software design, complex firmware or application software is decomposed into independent modules. Good modular design aims for maximum cohesion (all elements inside a module work together toward a single task) and minimum coupling (minimal interdependence between separate modules).
Cohesion (Intra-Module Focus — Ranked Worst to Best): Cohesion measures how closely related the responsibilities and elements within a single module are:
| Level | Quality | Description |
|---|---|---|
| 1. Coincidental | Worst | Elements are grouped arbitrarily with no meaningful functional relationship. |
| 2. Logical | Poor | Elements perform logically similar tasks (e.g., all I/O routines) selected by an external control flag. |
| 3. Temporal | Low | Elements are grouped only because they execute at the same time (e.g., an init_all() startup routine). |
| 4. Procedural | Moderate | Elements are grouped because they follow a fixed procedural sequence of execution. |
| 5. Communicational | Good | Elements operate on the same input/output data record or share the same peripheral device. |
| 6. Sequential | Very Good | Output from one element serves directly as input to the next (e.g., read_adc scale filter). |
| 7. Functional | Best (Highest) | Every element in the module contributes exclusively to performing one single, well-defined task. |
Coupling (Inter-Module Dependency — Ranked Best to Worst): Coupling measures the degree of interconnection and dependency between different modules:
| Type | Quality | Description |
|---|---|---|
| 1. Data Coupling | Best (Loosest) | Modules communicate solely by passing elementary local data values as function arguments. |
| 2. Stamp Coupling | Good | Modules pass a composite data structure (struct) when the receiver only needs a subset of its fields. |
| 3. Control Coupling | Moderate | One module passes a control flag or mode code that dictates internal branching in another module. |
| 4. Subclass Coupling | Moderate (OOP) | Dependency between a derived child class and its parent base class in object-oriented inheritance. |
| 5. Common Coupling | Poor | Multiple modules read and write shared global data areas (e.g., C extern globals), risking side effects. |
| 6. Content Coupling | Worst (Tightest) | One module directly reads/modifies internal data or branches into the instructions of another module. |
Cohesion measures how tightly elements within a single module belong to one unified task (ranked worst-to-best: Coincidental, Logical, Temporal, Procedural, Communicational, Sequential, Functional). Coupling measures interdependence between modules (ranked best-to-worst: Data, Stamp, Control, Subclass, Common, Content). Well-engineered instrumentation software maximizes functional cohesion and minimizes coupling toward data coupling.