| Coupling: Coupling is a property of a collection of modules. Coupling is the measure of interdependence between modules. Coupling is an indication of how modules are connected by data.
Example: Two modules can share the same pieces of data, or one module can pass its data into the other module. In general, we try to reduce coupling - we try to make sure our modules do not depend on each other.
Low coupling: A module with a low degree of interdependence from other modules is said to show low or loose coupling. Loose coupling is more
desirable, because a particular module is not tied to a program, and it can easily be placed in other programs without the programmer having to worry about the data being used.
High coupling: A module with a high degree of dependence on other modules is said to show high or tight coupling. If two modules are tightly coupled, it would be difficult to re-use one of them, because in the program you place one of the modules, it would have to use the same data.
Example:
Lets look at an example, so we can understand this concept better. Below is a program based on a game that children often play: A player picks a
color, type of car, and a number, and another player uses this information to make up a "fortune" for the first player. Trace the code below:
start
declare variables ----[ char color
[ char car
[ num a Number
get Inputs
display Fortune
end
get Inputs()
print "Enter your favorite color."
get color
print "Enter your dream car."
get car
print "Enter your favorite number."
get a Number
return
display Fortune()
print "You are going to live in a "
print color, " house, drive a "
print car, " and have ", number, " kids!
return
How re-usable are the modules in this program? If we tried to use the display Fortune() module in another program, we would have to make sure that this program used global variables called
"color", "car", and "a Number". This is not a very re-usable program! Also, what if you wanted to add or change one of the variables? You would have to make the addition or change in more than one location in this program, plus make the same change in all the other programs where you use this module!
This is a good example of high coupling.
|
Control coupling: A form of coupling in which control flags are passed between modules so that one module controls the sequence of execution in another
module. This type of coupling is typically used when a module does a number of function and only one of them has to be done at a time.
Example 1:

Type of Record flag:
1 means get next master record
2 means get next transaction record
3 means get both
Example 2:
Suppose we have written a common module which adds, modifies, deletes, prints, and displays records from a file. We can only do one of the above five activities at a given
time. From the calling module, a flag will have to be passed to indicate the type of activity to be done.
This logic can be applied to an Interest computation module, which calculates simple and compound interest. A flag could be passed to indicate the type of interest to be computed.
back to top
|