Intermodule Coupling
Coupling is the measure of the interdependence of one module to another.
Modules should have low coupling. Low coupling minimizes
the "ripple effect" where changes in one module cause errors in
other modules.
No Direct Coupling
These are independent modules and so are not really components
of a single system.
Data Coupling
Two modules are data coupled if they communicate
by passing parameters. This has been told to you
as a "good design principle" since day one of your
programming instruction.
Diagram
Stamp Coupling
Two modules are stamp coupled if they communicate via a
passed data structure that contains more information than
necessary for them to perform their functions.
Diagram
Control Coupling
Two modules are control coupled if they communicate using at least
one "control flag".
Diagram
Common Coupling
Two modules are common coupled if they both share the same
global data area. Another design principle you have been
taught since day one: don't use global data.
Diagram
Content Coupling
Two modules are content coupled if:
- one module changes a statement in another (Lisp was famous for this ability)
- one module references or alters data contained inside another module
- one module branches into another module
Examples
-
Type 2 can be done in, say, Pascal by using the language
scope rules to do non-local referencing... read and write the
values of variable in one procedure from another one (assuming
a procedure is considered a module)
-
A worse example of type 2 is if you use a language like Simula
in which you can create objects (data and procedures to operate
on that data, in a module) but then you violate the object boundaries
by directly reading and writing the variable in the object. Later
OO languages (C++, Eiffel) prevent this, but earlier ones do not.
-
Type3 can be done in Pascal... branch from one procedure to a
label in another... using scope rules.