What are the differences between cohesion and coupling of components in a system?
sobes.tech AI
Answer from AI
Cohesion is a measure of how closely related the elements within a single component or module are and how well they perform a single task. High cohesion means that all parts of the component are focused on solving one specific problem, which simplifies maintenance and understanding of the code.
Coupling of components refers to the degree of dependency between different system components. Low coupling means that changes in one component have minimal impact on others, increasing flexibility and making system scaling easier.
In summary:
- Cohesion is internal consistency and focus within a component.
- Coupling of components is the degree of dependency and interaction between different components.
Example: In Python, a module with functions that all work on the same task (e.g., string processing) has high cohesion. If this module heavily depends on another module (e.g., a database), then there is high coupling between them.