Concept:
In modular design, "Cohesion" refers to the degree to which the elements inside a module belong together. The general rule of thumb in software engineering is to aim for High Cohesion and Low Coupling. High cohesion means a module does exactly one thing and does it completely.
Step 1: The Hierarchy of Cohesion.
Cohesion levels are ranked from worst (lowest) to best (highest):
• Coincidental (Worst): Elements are put together randomly.
• Logical: Elements are put together because they perform similar tasks (e.g., all I/O functions).
• Temporal: Elements are grouped because they occur at the same time (e.g., initialization).
• Procedural: Elements are grouped because they follow a specific sequence of execution.
• Communicational: Elements operate on the same data.
• Sequential: Output of one part is input to another.
• Functional (Best): Every part of the module is necessary for the execution of a single, well-defined task.
Step 2: Why Functional Cohesion is Best.
A functionally cohesive module is highly reusable, easy to understand, and easy to maintain. If a module calculates "Tax Amount" and nothing else, you can use it anywhere you need tax calculations without worrying about side effects or unnecessary code.
Step 3: Conclusion.
Because functional cohesion represents the most focused and singular type of module design, it is the most desirable level in software engineering.