|
|
|
|
|
Control abstraction can serve as a guideline for deciding which modules to code as functions and which to code directly. If a module contains a control structure, it is a good candidate for being implemented as a function. For example, function FindLast lacks control abstraction. Its body is a sequence of two statements, which could just as well be located in the PrintLast function. But even if a module does not contain a control structure, you still want to consider other factors. Is it lengthy, or is it called from more than one place? If so, you should use a function. |
|
|
|
|
|
|
|
|
|
Somewhat related to control abstraction is the concept of functional cohesion, which states that a module should perform exactly one abstract action. |
|
|
|
|
 |
|
 |
|
|
Functional Cohesion The principle that a module should perform exactly one abstract action. |
|
|
|
|
|
|
|
|
|
If you can state the action that a module performs in one sentence with no conjunctions (ands), then it is highly cohesive. A module that has more than one primary purpose is lacking in cohesion. For example, function PrintLast skips the remainder of the first name and prints the last name; a more cohesive design would do away with PrintLast and simply call FindLast and PrintName. Note that PrintLast is also lacking in control abstraction. |
|
|
|
|
|
|
|
|
|
A module that only partially fulfills a purpose also lacks cohesion. Such a module should be combined with whatever other modules are directly related to it. For example, it would make no sense to have a separate function that prints the first letter of the last name because printing the last name is one abstract action. |
|
|
|
|
|
|
|
|
|
A third and related aspect of a module's design is its communication complexity, the amount of information that passes through a module's interface. A module's communication complexity is often an indicator of its cohesiveness. Usually, if a module requires a large number of parameters, it is either trying to accomplish too much or it is only partially fulfilling a purpose. You should step back and see if there is an alternative way of dividing up the problem so that a minimal amount of information is communicated between modules. |
|
|
|
|
 |
|
 |
|
|
Communication Complexity A measure of the quantity of information passing through a module's interface. |
|
|
|
|