Lecture 7: Software Design (Part II) Dr Valentina Plekhanova University of Sunderland, UK http://www.cet.sunderland.ac.uk/~cs0vpl/SE-Com185.htm
Low-level Design Also known as procedural or functional design: the design of the internal workings of a module; the fine details of the system; adds to the high level design details kept separate from the high level design, for clarity. Lecture 7 Valentina Plekhanova
Low-level Design If our designs are good, each procedure or function will only be required to carry out a fairly small and specific subtask. We now need to consider the design of the code that will carry out each of the identified subtasks. Once that is done, it should be fairly easy to translate each low-level design into program code. Lecture 7 Valentina Plekhanova
Low-level Design The actual choice of design representation to use is not important, designers have their own favourite methods. It is a matter of individual choice (unless you work for an organisation that imposes a particular design representation) as to the method of design representation you use to design low-level code. What all low-level design representation methods do is to portray in a way that is not specific to any one programming language. Lecture 7 Valentina Plekhanova
Low-level Design define input data; assign data to a variable; define output data from the module; define another (sub-) modules that can be 'called up' from this module. Lecture 7 Valentina Plekhanova
Low-level Design 4 main methods: pseudo code flow charts JSP Nassi-Shneiderman diagrams Lecture 7 Valentina Plekhanova
Low-level Design:Basic Constructs All these 4 main methods of producing low-level design documents are based on 3 basic constructs: sequence; selection; iteration (repetition) . Lecture 7 Valentina Plekhanova
Low-level Design Sequence is a linear progression where one task is performed sequentially after another. Iteration: WHILE is a loop with a simple conditional test at its beginning. Selection: IF-THEN-ELSE is a decision in which a choice is made between two alternative courses of action. Lecture 7 Valentina Plekhanova
Low Level Design Although these constructs are sufficient, it is often useful to include three more constructs: REPEAT-UNTIL is a loop with a simple conditional test at the bottom. FOR is a special loop in which an index variable is automatically initialised, incremented, and tested. CASE is a multiway branch (decision) based on the value of an expression. CASE is a generalisation of IF-THEN-ELSE. Lecture 7 Valentina Plekhanova
Basic Sections There are usually 3 sections to all Low-level designs: initialisation, processing, and termination. Lecture 7 Valentina Plekhanova
Low Level Design: Initialisation Initialisation section includes opening files, reading the first record, and, if necessary, printing page and report headings. Lecture 7 Valentina Plekhanova
Low Level Design: Processing Processing section includes DO statements to show repetitive tasks that are performed on each record in the file – there are two ways to show this loop: DO while data remains Processing steps Read next record END DO Lecture 7 Valentina Plekhanova
Low Level Design: Processing DO until end-of-file Processing steps Read next record END DO Lecture 7 Valentina Plekhanova
Low Level Design: Termination Termination section includes what happens at the very end of the program, such as closing the files and stopping the program. Lecture 7 Valentina Plekhanova
What is Pseudocode? Pseudocode is simply a way of describing the steps to the solution of a programming task, using a few English words in a structured way, though not in any particular programming language. Instead, or in combination, we can use program flowcharts. Lecture 7 Valentina Plekhanova
Pseudocode: Important Notes Each textbook and each individual designer may have their own personal style of pseudocode. Pseudocode is not a rigorous notation, since it is read by other people, not by the computer. There is no universal "standard" for the industry, but for instructional purposes it is helpful if we all follow a similar style. Lecture 7 Valentina Plekhanova
Examples of Pseudocode: Example 1 - The problem is to find the roots of a quadratic equation. Step 1 Prompt for and read the coefficients a, b, and c Step 2 If a = 0, do steps 3,4 Step 3 If b = 0 also, Error message: "no roots" and exit Step 4 Write single root -c/b and exit Step 5 Set d = b^2 - 4*a*c and if d < 0 Error message: "not real" and exit Step 6 Set s = -(b + sqrt(d)*sign(b))/2 Step 7 Set x1 = s/a. Write this first (robust) root Step 8 Set x2 = c/s. Write this second (robust) root. Step 9 Set x3 = -(b - sqrt(d)*sign(b))/(2*a). Write this second (risky) root. Lecture 7 Valentina Plekhanova
Example 2: Pseudocode prompt the user to input the number of days; user inputs the number of days; multiply the number of days by 7 hours; display the total hours with an output prompt. Lecture 7 Valentina Plekhanova
Low-level Design: Flow charts A flowchart is a pictorial representation of the logic in a computer program Based on the 3 basic constructs, sequence, selection and iteration. In flow chart, certain shapes have special meaning, and arrows are used to connect pieces of the flowchart. Lecture 7 Valentina Plekhanova
Low-level Design: Flow charts Used to indicate the beginning (start) or end (stop) of a computer program or subroutine. Used to indicate some type of input or output, such as opening or closing Files. Also known as a decision symbol, this is used to indicate a decision to be made, choices based on logic – an “if” statement Arrows are used to show the flow of the program – to show where the next item is located. Lecture 7 Valentina Plekhanova
Some Examples: Pseudocodes & Flow Charts Lecture 7 Valentina Plekhanova
Flow chart – Sequence Sequential control is indicated by writing one action/task after another, each action/task on a line by itself, and all actions/tasks aligned with the same indent. The actions/tasks are performed in the sequence (top to bottom) that they are written. Lecture 7 Valentina Plekhanova
Flow chart – Selection: IF-THEN-ELSE Binary choice on a given Boolean condition is indicated by the use of four keywords: IF, THEN, ELSE, and ENDIF. The general form is: IF condition THEN sequence 1 ELSE sequence 2 END IF The ELSE keyword and "sequence 2" are optional. If the condition is true, sequence 1 is performed, otherwise sequence 2 is performed. Lecture 7 Valentina Plekhanova
Flow chart – Selection: IF-THEN-ELSE Example IF hours > 35 THEN Display overtime message ELSE Display regular time message END IF Lecture 7 Valentina Plekhanova
Flow chart - Iteration (e.g. for, while) This loop is a specialised construct in which an index variable is automatically initialised, incremented and tested. Two keywords, FOR and END FOR are used. Example: The general form is: FOR index = start to finish sequence END FOR At the initiation of the loop, the index variable is set to the starting value. At the end of each iteration, the index variable is automatically incremented. The loop repeats until the index value reaches the finish value. Lecture 7 Valentina Plekhanova
Flow chart - Iteration: WHILE The WHILE construct is used to specify a loop with a test at the top. The beginning and ending of the loop are indicated by two keywords WHILE and END WHILE. The general form is: WHILE condition sequence END WHILE Example: WHILE number of days < 6 Compute hours as number of days * hours Lecture 7 Valentina Plekhanova
Flow chart - Iteration: WHILE The loop is entered only if the condition is true. The "sequence" is performed for each iteration. At the conclusion of each iteration, the condition is evaluated and the loop continues as long as the condition is true. Lecture 7 Valentina Plekhanova
Low-level Design: Important Notes Time spent on the design stage of the development cycle will lead to less time spent on testing, debugging and re-writing your programs to make them work properly. Lecture Notes are based on materials taken from Books: Pfleeger; Sommerville; Vliet (see References Site). Lecture 7 Valentina Plekhanova
Week 8: 24.04.2003-28.04.2003 Project Control Session Tutorial Time: 10 minutes for each Team Students will present project file, particularly Schedule, plus any project documentation. Students will describe where they are in the project and any problems encountered. During the discussion reviewers will ask to see evidence of deliverables for any tasks that are complete to determine whether they have in fact been done. Lecture 7 Valentina Plekhanova