Coupling refers to the degree of interdependence between software modules.
High coupling means that modules are closely connected and changes in one
module may affect other modules. Low coupling means that modules are
independent and changes in one module have little impact on other modules.
Cohesion refers to the degree to which elements within a module work together
to fulfill a single, well-defined purpose. High cohesion means that elements are
closely related and focused on a single purpose, while low cohesion means that
elements are loosely related and serve multiple purposes.
Types of Coupling:
Data Coupling: If the dependency between the modules is based on the
fact that they communicate by passing only data, then the modules are said
to be data coupled. In data coupling, the components are independent of
each other and communicate through data. Module communications don’t
contain tramp data. Example-customer billing system.
Stamp Coupling In stamp coupling, the complete data structure is passed
from one module to another module. Therefore, it involves tramp data. It may
be necessary due to efficiency factors- this choice was made by the
insightful designer, not a lazy programmer.
Control Coupling: If the modules communicate by passing control
information, then they are said to be control coupled. It can be bad if
parameters indicate completely different behavior and good if parameters
allow factoring and reuse of functionality. Example- sort function that takes
comparison function as an argument.