Modularization 279
module. If we were looking for a tag to describe modularization based
on the criterion of information hiding, we might say object based
simply because the structure that drops out is one that emphasizes
objects rather than actions.
Here is a modularization problem originally proposed by Parnas in his
discussion of information hiding. It is about the right size to justify
care in modularization, without being unwieldy for illustrative purposes.
The specication is as follows:
Input: Text le consisting of several lines of several words each.
Output: Text le consisting of all circular shifts of all lines of the
input, in alphabetical order.
Denition: A circular shift is done by removing the rst word from a
line and appending it to the end of the line.
Example:
Input (All circular shifts) Output
the quick brown fox the quick brown fox brown fox the quick
jumps over quick brown fox the dog the lazy
the lazy dog brown fox the quick fox the quick brown
fox the quick brown jumps over
jumps over lazy dog the
over jumps over jumps
the lazy dog quick brown fox the
lazy dog the the lazy dog
dog the lazy the quick brown fox
(Note that giving an example clears some potential ambiguity: the
alphabetization goes on to subsequent words after the rst.)
Modularization A is based on a top-down decomposition.
1. Input
Read lines into memory
Set up pointer to start of each line
2. Circular shift
Add pointer to start of every word
3. Alphabetizing
Sort pointers (Sort function looks at words being pointed to and
checks alpha order)
4. Output
Go through pointer list sequentially.
For any entry, print out until CR
Go back to previous CRthen print out from there to pointer
position.
5. Master control
Sequencing, error messages, etc.
This decomposition into modules has implicitly dened the data
structures that will be used. It has also introduced design decisions
which have global effects. For example, the decision has been made to
12.4 A modularization
example

Get Software Design for Engineers and Scientists now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.