Sunteți pe pagina 1din 20

Structured Program Design

What is Structured Program Design?


A method for designing and specifying programs in a diagrammatic form Based on the premise that all programs are constructed using three basic constructs :Sequence
Performing process blocks one after another

Iteration
Performing process blocks more than once An asterisk (i.e. *) in the top right hand corner of a rectangle representing a process block indicates that it is iterated

Selection
Performing process blocks selectively based on identified criteria A circle (i.e. O or 0) in the top right hand corner of a rectangle representing a process block indicates that it is performed based on identified selection criteria

What is Structured Program Design?


Sequence

Selection

D
Else

Iteration

Condition

Condition
O

H *

Structured Program Design assumes a read-ahead approach to the handling of file records and database sets This means that you must :Attempt to read the first record in the file or set before performing the processing for those records Attempt to read the next record in the file or set as the last action in the processing for those records

Drawing the Diagram


Process blocks are represented in a diagram by rectangular boxes Process blocks are arranged in hierarchical levels A box at one level is a summary of all the boxes that are suspended from it Connection between the levels are represented by lines Each box should be given a meaningful name that summarises the processing it performs Each boxes should also be given reference codes/numbers that clearly indicate the parentage of the box and its sequence of performance within the parent process

Drawing the Diagram


For example
Program

11

21

22

23

31

111

112

221

222

2211

Drawing the Diagram


If boxes representing the same processing are identified within a diagram they can be placed at the bottom of the diagram to be coded as sub-routines or even external sub-modules (if the processing involved is used several times throughout a system)
Program A AA S2 S1 BAA S2 S1 S21 S3 S3 BA BAB B * BB BAC C CA BAD S1
O

S3

S2

Drawing the Diagram


Do not mix boxes representing the alternatives for a selection on the same level as boxes representing sequential or iterative processing because it will make the diagram unclear and confusing
B1
Condition Condition Condition Else Condition
O

B1

B11 *

B12

B13

B14

B15

B11 *

B12

B13
Else

Condition Condition

WRONG !!

B131

B132

B133

RIGHT !!

Methodology
There are two methods of developing the diagram :Bottom Up (Jackson Structure Program Design) Method
Is based on an analysis of the input and output data structures and identification of the tasks that have to be performed to get from input to output Tasks are then grouped together in logically related units These units are then grouped together higher level units and this process is repeated until all units are grouped under one top level until (i.e. the program)

Top Down (Decomposition) Method


Is based on an analysis and clear understanding of the function(s) to be performed and an identification of the tasks that have to be performed to execute those functions Each high level task is broken down into sub-tasks Each sub-task is then further broken down and this process repeated until no further break down is possible

Methodology (1)
Example of Bottom-Up approach
Program function is to update file B with information from file A (NB Both files are sorted into the same sequence and every record on file A has a corresponding record on file B and vice versa) Data related actions
Access data on A Access data on B Update data on B using data from A

Tasks related to data actions


Open file A / Read file A Open file A / Read file B Move data from current A to current B / Write current B back to file Read next file A Read next file B At end close file A At end close file B

Methodology (1)
Group tasks together into logically related units
Open file A / Open file B Read file A / Read file B Move data from current A to current B / Write current B back to file Read next file A / Read next file B At end close file A / close file B

Identify conditions Draw diagram


Access data

Program Close file A Close file B

Process data

Until end of file


Open file A Open file B Read A Read B Update data

*
Read A Read B

Move data from A to B Write B to file

Methodology (1)
Note that when drawing the diagram this methodology does not allow a component block to own blocks of more than one type Therefore in the diagram above we have to introduce component block Process data to own process block Update data instead of having this block owned directly by Program Also note that process block Read A / Read B is repeated under process blocks Access data and Update data this means that this process block can be taken out as a common subroutine within the program

Methodology (2)
Example of Top-Down approach
Program function is to update file B with information from file A (NB Both files are sorted into the same sequence and every record on file A has a corresponding record on file B and vice versa) Identify Level 2 functions (NB Level 1 is the program)
Initial routine Main program routines performed until end of files Closing routines

Methodology (2)
Identify Level 3 functions
Initial routine
 Open files  Read files

Main program routines performed until end of files


 Update data  Read files

Closing routines
 Close files

Methodology (2)
Identify Level 4 functions
Initial routine
 Open files Open file A Open file B  Read files Read file A Read file B

Main program routines performed until end of files


 Update data Move data from A to B Write B back to file  Read files Read file A Read file B

Closing routines
 Close files Close file A Close file B

Methodology (2)
Draw Diagram
Program

Until end of file


Access data Update data

Close file A Close file B Read A Read B

Open file A Open file B

Read A Read B

Move data from A to B Write B to file

Ideally if the decomposition has been done correctly the bottom layer of boxes in each branch should contain no PERFORM or IF statements Note that conditions are identified as the functions are being decomposed

Methodology (2)
Also note that process block Read A / Read B is repeated under process blocks Access data and Update data this means that this process block can be taken out as a common subroutine within the program Also note that generally when drawing a Top-down structure diagram the top two level will almost always be the same as shown in the diagram below
Program

Condition(s)
Start Processes Main Processes

Finish Processes

Advantages
Non-Inspirational
The use of structured program design does not rely on insists, invention or creativity

Rational
It is based on reasonable principles well developed and well defined

Teachable
Being collections of well defined steps it is possible to explain and show how these methods are applied and how they work

Consistent
Given a single problem for analysis different programmers or systems analysts will generally come up with the same program design

Advantages
Simple
These methods do not involve over complex rules or cumbersome procedures

Universal
By using these methods program specifications and designs are produced that can be implemented in any language

Disadvantages (?)
Mechanical not Intuitive
Because these methods are largely mechanical and standardised they do not allow systems analysts or programmers to be intuitive

Increases Regimentation
Does not allow systems analysts and programmers to use their imagination and come up with radical and innovative designs

Subject to Tighter Control and Scrutiny


Because these methods are systematic and not innovative the work produced by the systems analysts and programmers can be easily reviewed by their supervisors

Disadvantages
Method 1
Because this method is based on the input and/or output data structures it means that these must be very clearly defined before the systems analysts and programmers can start work - no data structures means no place to start Any changes to the data structure involved may require major rework of the specification and program design

Method 2
Because this method is based on the program functionality it means that this must be very clearly defined and identified before the systems analysts and programmers can start work Any changes to the program functionality may require major rework of the specification and program design

S-ar putea să vă placă și