"Chapter 8: First Steps in Modularisation": Simple Program Design
"Chapter 8: First Steps in Modularisation": Simple Program Design
Modularisation
Modularisation means dividing a problem into
subtasks. As problems become more complicated,
the major task should be subdivided into subtasks to
make it easier to understand the problem. Suppose
the major task is to make an apple pie. Some
subtasks of making the pie are: buying the
ingredients, making the ingredients, and baking the
pie.
The mainline
The mainline module controls the program by tieing
all the other modules together. With the use of good
module names, the mainline module becomes the
top level outline for the program.
Let's revisit two algorithms from chapter 4.
Further modularisation
The above example could also have been designed
to use a mainline and three modules, one each of the
main processing steps in the defining diagram as
follows:
Read three characters
Sort three characters
Print three characters
A Defining Diagram
Here is the IPO chart.
B Solution algorithm
Here is the new solution algorithm
Communication Between
Modules
The fewer and simpler the communications between
modules, the better. This flow of information, called
intermodule communication, can be accomplished by
the scope of the variable (local or global data) or the
passing of [arameters.
Scope of a variable
The scope of a variable is the portion of the program
in which that variable has been defined and to which
it can be referred.
Global data
Global data can be accessed by every module in the
program. Not all data should be global!
Local data
Variables defined within a subordinate module are
called local variables. They can only be referenced by
this modules and modules called by this module.
Side effects
Side effects are where a module changes values of
variables in other parts of the program.
Passing parameters
Passing parameters means a calling module transfers
information to the called module. Under some
circumstanes, the called module also returns
information to the calling module. Structure charts
show this by using arrows
Steps In Modularisation
Expected results
Here are the expected results.
Expected results
Here are the expected results with sample titles and
column headings.