Presentation is loading. Please wait.

Presentation is loading. Please wait.

IMSE Lecture Week 6 - Low Level Design Summary of last week: u Transform Analysis - 4 steps: 1 annotate the DFD (without redrawing it) 2 draw the intermediate.

Similar presentations


Presentation on theme: "IMSE Lecture Week 6 - Low Level Design Summary of last week: u Transform Analysis - 4 steps: 1 annotate the DFD (without redrawing it) 2 draw the intermediate."— Presentation transcript:

1 IMSE Lecture Week 6 - Low Level Design Summary of last week: u Transform Analysis - 4 steps: 1 annotate the DFD (without redrawing it) 2 draw the intermediate diagram 3 draw the first cut structure chart 4 refine the structure chart u We’ve covered the first 3 steps so far

2 Delaying Step 4 u step 4 (refining the structure chart) must be delayed u first we need to think about low-level design issues u long diversion needed before we can produce a final refined structure chart for the system

3 High Level Design u high level design documents such as structure charts show: - the overall system design - how the program is decomposed into separate modules - which modules call which other ones - how they communicate via data and flags u they do not show: - the order in which the modules are called - the number of times they are called if it’s more than once - the condition(s) determining optional/conditional invocation - the internal workings of the modules

4 Low Level Design u Also known as procedural or functional design: - the design of the internal workings of a module - the design of the internal workings of a module - the fine details of the system - the fine details of the system - adds to the high level design - adds to the high level design - details kept separate from the high level design, for clarity - details kept separate from the high level design, for clarity u 4 main methods: - pseudo code (most popular nowadays) - pseudo code (most popular nowadays) - JSP - JSP - flow charts - flow charts - Nassi-Shneiderman diagrams - Nassi-Shneiderman diagrams

5 3 Basic Constructs u all these 4 main methods of producing low-level design documents are based on 3 basic constructs: - sequence - selection - iteration u all the internal logic of our modules can be expressed using only these 3 constructs

6 Pseudo code u Use of words rather than diagrams, good but not visual u More closely resembles the coded-up module u various terminology exists, e.g.FUNCTION, procedure, loop until, while … we will use COM168 version. if sex = male write “Mr.” else write “Ms.” ifend write name

7 JSP u Original concepts developed by Dijkstra, but made popular by Michael Jackson in the JSP method * repetition u Show logical order and control of processing selection o o o o

8 Nassi-Shneiderman abstract example do this do this then this then this while true while true T if this is true F T if this is true F do this do this while true do this while true do this finally do this finally do this

9 Flow charts u traditional method, now out of favour u the reason is because flow charts do not enforce good design practices, as they may produce modules with very poor flow of control, i.e. “spaghetti code” u again based on the 3 basic constructs, sequence, selection and iteration

10 Flow chart - sequence 1st task add 10 2 tasks, performed to a sequentially, e.g. to a sequentially, e.g. a = a + 10 a = a + 10 2nd task deduct b = b - 2 2 from b 2 from b

11 Flow chart - selection e.g. e.g.condition T F T F if k > max if k > max write “k > max” write “k > max” then else else part part write “k <= max” ifend ifend T and F may be right, left or below the diamond, and the then or else part may be directly below the diamond - wherever works best T and F may be right, left or below the diamond, and the then or else part may be directly below the diamond - wherever works best

12 Flow chart - iteration (e.g. for, while) e.g. deduct 1 loop while k > min deduct 1 loop while k > min from k write k from k write k loop k = k-1 loop k = k-1 tasks loopend tasks loopend print k print k k > T k > T min loop condition min loop condition F

13 Flow chart - iteration (e.g. do while, or repeat until) e.g. loop loop loop tasks print k k = k-1 loopend when k <= min loopend when k <= min k>min k>min loop T loop T condition conditionF

14 Flow chart - selection (e.g. else if, case) k > T print k > 100 e.g. k > T print k > 100 e.g. 100 100 F if k > 100 F if k > 100 k > T print k > 50 write “k > 100” k > T print k > 50 write “k > 100” 50 elseif k > 50 50 elseif k > 50 F write “k > 50” F write “k > 50” elseif k > 0 elseif k > 0 k > T print k > 0 write “k > 0” k > T print k > 0 write “k > 0” 0 ifend 0 ifend F

15 Pseudocode and Stepwise Refinement - Top Mark Example u using pseudocode and stepwise refinement design the internal details of a single module whose role is to find the top mark from a set of marks terminated with 999 u 2 general principles: –design the algorithm in steps, and always walk through it with test data after each refinement –when designing algorithms with loops always take care with pre-loop initialisationpre-loop initialisation always exiting from the loopalways exiting from the loop post-loop tidying uppost-loop tidying up u NB there will almost always be more than one correct solution

16 Step 1 initialisations initialisationsloop read mark read mark if mark > max if mark > max max <- mark max <- mark endif endif loopend when mark = 999 write max u decompose into 3 parts - start up, process, end u always leave initialisations until after the main processing is clearer u after clarifying the main processing and walking through it with some test data we see that step 2 needs to include the initialisation of max

17 Step 2 max = 0 max = 0loop read mark read mark if mark > max if mark > max max <- mark max <- mark endif endif loopend when mark=999 write max u this looks good, but provides us with an unreliable algorithm u it would not always give the correct result - walk through the algorithm with all negative marks - the max mark would be incorrectly displayed as 0 u a more reliable algorithm needs to be designed, to cater for unlikely possibilities which may one day happen

18 Step 3 read 1st mark read 1st mark max = 1st mark max = 1st markloop if mark > max if mark > max max <- mark max <- mark endif endif read next mark read next mark loopend when mark = 999 write max u this looks better, but is still not perfect u walk through the algorithm with an empty set of marks u the max mark would be incorrectly set to 999 u the loop would never exit (common error) as processing would stop at input next mark

19 Final Level of Refinement read 1st mark read 1st mark max = 1st mark max = 1st mark loop while mark not equal to 999 if mark > max if mark > max max <- mark max <- mark endif endif read next mark read next markloopend if max not equal to 999 write max write max endif endif u solution uses sequence, selection and repetition u common mistake in previous steps - listing some of the component parts in the wrong order -the 1st mark was originally input inside the loop -loop condition was tested at the end, not the start of the loop u walking through with test data at each step helps find correct ordering u final algorithm is now fully designed and ready to be coded up


Download ppt "IMSE Lecture Week 6 - Low Level Design Summary of last week: u Transform Analysis - 4 steps: 1 annotate the DFD (without redrawing it) 2 draw the intermediate."

Similar presentations


Ads by Google