21.08.2013 Views

Software Engineering for Students A Programming Approach

Software Engineering for Students A Programming Approach

Software Engineering for Students A Programming Approach

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

130 Chapter 10 ■ Data structure design<br />

10.5 ● Structure clashes<br />

In a minority of problems, the two or more data structures involved cannot be<br />

mapped onto a single program structure. The method terms this a structure clash.<br />

It happens if we try to use the method to design a program to solve the following<br />

problem.<br />

Design a program that inputs records consisting of 80 character lines of words and<br />

spaces. The output is to be lines of 47 characters, with just one space between words.<br />

This problem looks innocuous enough, but it is more complex than it looks. (Have<br />

a go if you don’t agree!) A problem arises in trying to fit words from the input file neatly<br />

into lines in the output file. Figures 10.11 and 10.12 show the data structure diagrams<br />

<strong>for</strong> the input and output files. Superficially they look the same, but a line in the<br />

input file does not correspond to a line in the output file. The two structures are fundamentally<br />

irreconcilable and we cannot derive a single program structure. This situation<br />

is called a structure clash.<br />

Although it is difficult to derive a single program structure from the data structure<br />

diagrams, we can instead visualize two programs:<br />

■ program 1, the breaker, that reads the input file, recognizes words and produces<br />

a file that consists just of words.<br />

■ program 2, the builder, that takes the file of words created by program 1 and<br />

builds it into lines of the required width.<br />

We now have two programs together with a file that acts as an intermediary between<br />

the programs.<br />

Input<br />

file<br />

Figure 10.11 Data structure diagram <strong>for</strong> input file<br />

*<br />

Line<br />

Output<br />

file<br />

*<br />

Line<br />

Figure 10.12 Data structure diagram <strong>for</strong> output file

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!