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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

10.5 Structure clashes 133<br />

Let us review the situation so far. We drew the data structure diagrams, but then saw<br />

the clash between the structures. We resolved the situation by identifying two separate<br />

programs that together per<strong>for</strong>m the required task. Next we examine the two file structures<br />

and identify a component that is common to both. (In the example program this<br />

is a word of the text.) This common element is the substance of the intermediate file<br />

and is the key to dealing with a structure clash.<br />

What do we do next? We have three options open to us.<br />

First, we might decide that we can live with the situation – two programs with an<br />

intermediate file. Perhaps the overhead of additional input-output operations on the<br />

intermediate file is tolerable. (On the other hand, the effect on per<strong>for</strong>mance might be<br />

unacceptable.)<br />

The second option requires special operating system or programming language facilities.<br />

For example, Unix provides the facility to construct software as collections of programs,<br />

called filters, that pass data to and from each other as serial streams called pipes.<br />

There is minimal per<strong>for</strong>mance penalty in doing this and the bonus is high modularity.<br />

For the above problem, we write each of the two programs and then run them with<br />

a pipe in between, using the Unix command:<br />

breaker < InputFile | builder > OutputFile<br />

or the DOS command:<br />

InputFile | breaker | builder > OutputFile<br />

in which the symbol | means that the output from the filter (program) breaker is used<br />

as input to the program (filter) builder.<br />

The third and final option is to take the two programs and convert them back into<br />

a single program, eliminating the intermediate file. To do this, we take either one and<br />

trans<strong>for</strong>m it into a subroutine of the other. This process is known as inversion. We will<br />

not pursue this interesting technique within this book.<br />

On the face of it, structure clashes and program inversion seem to be very complicated,<br />

so why bother? Arguably structure clashes are not an invention of the data structure<br />

design method, but a characteristic inherent in certain problems. Whichever<br />

method that was used to design this program, the same essential characteristic of the<br />

problem has to be overcome. The method has there<strong>for</strong>e enabled us to gain a fundamental<br />

insight into problem solving.<br />

In summary, the data structure design method accommodates structure clashes like<br />

this. Try to identify an element of data that is common to both the input file and the<br />

output file. In the example problem it is a word of text. Split the required program into<br />

two programs – one that converts the input file into an intermediate file that consists<br />

of the common data items (words in our example) and a second that converts the intermediate<br />

file into the required output. Now each of the two programs can be designed<br />

according to the normal data structure design method, since there is no structure clash

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

Saved successfully!

Ooh no, something went wrong!