What is cohesion and coupling in C language - What is cohesion and coupling - Cohesion and Coupling - Cohesion and coupling kya hai

What is cohesion and coupling in C language


Cohesion and coupling are two important concepts in software design that describe the quality of the relationships between components in a program.
 
Cohesion:

Cohesion refers to the degree to which the elements (functions, variables, and modules) within a software component (e.g., a module or a class) are related and contribute to a single, well-defined purpose or responsibility. High cohesion implies that the elements within the component are closely related and work together towards a common goal, making the component more focused and easier to understand, maintain, and modify.

In C language, you can achieve high cohesion by organizing related functions and data within a module, where each module serves a specific purpose or encapsulates a set of related functionalities. Functions within the module should operate on the same data or serve the same objective.
 
Low cohesion, on the other hand, implies that the elements within a component are loosely related or perform unrelated tasks, making the component less maintainable and harder to reason about.
 
Coupling:

Coupling refers to the level of dependency between different components (modules, classes, or functions) in a software system. It measures how much one component relies on another. Low coupling indicates that components are relatively independent and can be modified or replaced without affecting other parts of the system.

In C language, you can achieve low coupling by minimizing the dependencies between modules. Each module should have minimal knowledge of the internal workings of other modules. This is typically achieved by using well-defined interfaces and not accessing the internal data or functions of other modules directly.
 
High coupling means that changes in one component may require modifications in many other components, leading to a higher risk of errors and making the codebase less maintainable and flexible.
 
In general, it is desirable to have high cohesion and low coupling in software design. High cohesion helps ensure that each component has a clear, well-defined purpose, making the code more organized and readable. Low coupling reduces the interdependence between components, leading to more flexible and easier-to-maintain code.
 
Properly managing cohesion and coupling is crucial for creating robust and scalable software systems. It requires careful design and attention to the relationships between different parts of the codebase.

Comments