Cohesion and coupling
Cohesion and Coupling Cohesion measures the degree to which elements within a software module are related. A high cohesion indicates that elements are ti...
Cohesion and Coupling Cohesion measures the degree to which elements within a software module are related. A high cohesion indicates that elements are ti...
Cohesion measures the degree to which elements within a software module are related. A high cohesion indicates that elements are tightly intertwined and share common responsibilities, while a low cohesion indicates elements are loosely coupled.
Examples:
In a module for managing orders, cohesion could be achieved by grouping related functions together, such as 'order processing', 'payment handling', and 'customer management'.
A module for handling data could be more cohesive if it focused on data access and manipulation, instead of containing code for user interaction and report generation.
Coupling measures the degree to which elements in a software module are dependent on each other. A high coupling indicates that elements are dependent on each other heavily, while a low coupling indicates elements are independent of each other.
Examples:
In a module for building a calendar, coupling could be achieved by using a single library for date and time calculations.
A module for managing tasks could be less coupled if it used various components like task scheduling, task dependencies, and notification systems.
Importance of Cohesion and Coupling:
Maintainability: Cohesive and coupled modules are easier to understand and maintain, as changes in one module are less likely to break other parts of the software.
Testability: Cohesive modules are easier to test individually, as each element can be tested in isolation.
Scalability: Cohesive and coupled modules are easier to scale to larger projects, as adding new functionality can be done by adding code to specific modules.
Reusability: Cohesive modules can be reused in other projects, while coupled modules may require modifications for each project.
Additional Notes:
The degree of cohesion and coupling can be measured using various metrics, such as cyclomatic complexity, information flow analysis, and test coverage.
Achieving a good balance between cohesion and coupling is essential for creating robust and maintainable software.
Cohesion and coupling can be considered in both functional and non-functional requirements