Difference between Coupling and Cohesion
Coupling
Introduction
- In general, “coupling” refers to the degree to which two or more things are connected or intertwined.
- In general, coupling refers to the degree to which different components or modules of a system depend on each other.
Definition
- In computer science and software engineering, coupling typically refers to the degree to which two or more software components or modules depend on each other. In other words, coupling specifically refers to the degree of interdependence between software modules or components.
Characteristics
- Minimizing coupling in a software system can lead to more modular, flexible, and maintainable code.
Types of Coupling
- There are different types of coupling which are as follows:
-
-
Tight Coupling:
- This occurs when two or more components are heavily dependent on each other and cannot function independently.
- Tight coupling can make it difficult to modify or maintain the system because changes in one component can have unintended effects on others.
- In a tightly coupled system, since modules are highly dependent on each other and hence changes in one module can have a significant impact on other modules.
-
Loose Coupling:
- In contrast to tight coupling, loose coupling refers to a system in which components have minimal dependencies on each other. This makes it easier to modify or replace components without affecting the rest of the system.
- In a loosely coupled system, modules are relatively independent of each other and changes in one module have minimal impact on other modules.
-
Content Coupling:
-
This type of coupling occurs when one component modifies or relies on the internal workings of another component. This can create dependencies between the two components and make them difficult to change independently.
-
This refers to a situation where one module modifies or relies on the internal implementation details of another module.
-
-
Common Coupling:
- This refers to a situation in which two or more components share the same global data.
- This can lead to unintended interactions between components and make the system more difficult to maintain.
-
This occurs when multiple modules access the same global data or shared resources.
-
Control Coupling:
- This type of coupling occurs when one component controls the behavior of another component through parameters or function calls.
- This can create dependencies between the two components and make them difficult to modify or maintain independently.
-
This refers to a situation where one module controls the flow of another module by passing control information or parameters.
-
Data Coupling:
-
In a system with data coupling, modules share data through parameters, such as passing a data structure or object.
-
-
Stamp Coupling:
-
This occurs when modules share a large and complex data structure, but only use a small portion of it.
-
-
External Coupling:
- External coupling occurs when two or more components depend on the same external interface or service.
- This can create dependencies between components and make them difficult to change independently.
-
Cohesion
Definition
- In computer science, cohesion refers to the degree to which the elements of a module or program are related to each other and perform a single, well-defined function.
Characteristics
- A cohesive module or program is one in which its individual parts or components work together towards a common goal or objective.
- Cohesion is an important design principle in software development as it helps to ensure that programs are modular, maintainable, and scalable.
- High cohesion means that the elements within a module are strongly related and work together towards a common goal, while low cohesion means that the elements within a module are loosely related and may not have a clear purpose. A high degree of cohesion is generally desirable as it makes code easier to understand, modify, and test.
- In other words, High cohesion means that a module or component is focused and does a specific, well-defined task, while low cohesion means that it is doing too many things or that its responsibilities are not related.
Types of Cohesion
- There are several types of cohesion:
-
-
Functional cohesion:
-
This is the highest level of cohesion and occurs when a module or component performs a single, well-defined task or function.
- This occurs when the elements within a module or program are related by a single, well-defined function, such as all performing a specific calculation or task.
-
-
Sequential cohesion:
-
This occurs when the elements within a module or program are related by a specific sequence of operations, where the output of one operation becomes the input of the next.
-
-
Communicational cohesion:
-
This occurs when a module or component performs a set of tasks that are all related to a specific data structure or set of data.
-
The tasks may not be related to each other, but they all use the same data.
- This occurs when the elements within a module or program are related by a specific input or output data structure.
-
-
Procedural cohesion:
-
This occurs when a module or component performs a set of tasks that are related to each other and must be performed in a specific order.
-
The tasks are related to a specific procedure or algorithm.
- This occurs when the elements within a module or program are related by a specific sequence of steps or procedures.
-
-
Temporal cohesion:
- This occurs when a module or component performs a set of tasks that must be performed at the same time or during the same period.
-
Logical cohesion:
-
This occurs when a module or component performs a set of tasks that are related logically, but not necessarily functionally. The tasks may be related to a common theme or concept.
- This occurs when the elements within a module or program are related to a common function or purpose.
-
-
Coincidental cohesion:
-
This occurs when the elements within a module or program are unrelated and have no common purpose.
-
This is the lowest level of cohesion and occurs when a module or component performs a set of tasks that are unrelated and do not have any common theme or purpose.
-
-
0 Comments