+ All Categories
Home > Documents > Lecture 7: Software Design (Part II) Dr Valentina Plekhanova University of Sunderland, UK...

Lecture 7: Software Design (Part II) Dr Valentina Plekhanova University of Sunderland, UK...

Date post: 31-Mar-2015
Category:
Upload: sophia-villers
View: 218 times
Download: 0 times
Share this document with a friend
29
Lecture 7 Lecture 7 : : Software Software Design Design (Part II) (Part II) Dr Valentina Plekhanova Dr Valentina Plekhanova University of Sunderland, University of Sunderland, UK UK http://www.cet.sunderland.ac.uk/~cs0vpl/SE- http://www.cet.sunderland.ac.uk/~cs0vpl/SE- Com185.htm Com185.htm
Transcript
Page 1: Lecture 7: Software Design (Part II) Dr Valentina Plekhanova University of Sunderland, UK cs0vpl/SE-Com185.htm.

Lecture 7Lecture 7: : Software Design Software Design (Part II)(Part II)

Dr Valentina PlekhanovaDr Valentina Plekhanova

University of Sunderland, UKUniversity of Sunderland, UK

http://www.cet.sunderland.ac.uk/~cs0vpl/SE-Com185.htmhttp://www.cet.sunderland.ac.uk/~cs0vpl/SE-Com185.htm

Page 2: Lecture 7: Software Design (Part II) Dr Valentina Plekhanova University of Sunderland, UK cs0vpl/SE-Com185.htm.

Lecture 7 Valentina Plekhanova 2

Low-level DesignLow-level Design Also known as Also known as proceduralprocedural or or functionalfunctional

design: 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 details kept separate

from the high level design, for clarity.from the high level design, for clarity.

Page 3: Lecture 7: Software Design (Part II) Dr Valentina Plekhanova University of Sunderland, UK cs0vpl/SE-Com185.htm.

Lecture 7 Valentina Plekhanova 3

Low-level DesignLow-level Design If our designs are good, each procedure or If our designs are good, each procedure or

function will only be required to carry out a fairly function will only be required to carry out a fairly small and specific subtask. small and specific subtask.

We now need to consider the design of the code We now need to consider the design of the code that will carry out each of the identified subtasks. that will carry out each of the identified subtasks.

Once that is done, it should be fairly easy to Once that is done, it should be fairly easy to translate each low-level design into program translate each low-level design into program code.code.

Page 4: Lecture 7: Software Design (Part II) Dr Valentina Plekhanova University of Sunderland, UK cs0vpl/SE-Com185.htm.

Lecture 7 Valentina Plekhanova 4

Low-level DesignLow-level Design The actual choice of design representation to use The actual choice of design representation to use

is not important, designers have their own is not important, designers have their own favourite methods. favourite methods.

It is a matter of individual choice (unless you It is a matter of individual choice (unless you work for an organisation that imposes a particular work for an organisation that imposes a particular design representation) as to the method of design design representation) as to the method of design representation you use to design low-level code. representation you use to design low-level code.

What all What all low-level designlow-level design representation methods representation methods do is to portray in a way that is not specific to any do is to portray in a way that is not specific to any one programming language.one programming language.

Page 5: Lecture 7: Software Design (Part II) Dr Valentina Plekhanova University of Sunderland, UK cs0vpl/SE-Com185.htm.

Lecture 7 Valentina Plekhanova 5

Low-level DesignLow-level Design define input data;define input data; assign data to a variable; assign data to a variable; define output data from the module;define output data from the module; define another (sub-) modules that can define another (sub-) modules that can

be 'called up' from this module. be 'called up' from this module.

Page 6: Lecture 7: Software Design (Part II) Dr Valentina Plekhanova University of Sunderland, UK cs0vpl/SE-Com185.htm.

Lecture 7 Valentina Plekhanova 6

Low-level DesignLow-level Design 4 main methods:4 main methods: pseudo codepseudo code flow chartsflow charts JSP JSP Nassi-Shneiderman diagramsNassi-Shneiderman diagrams

Page 7: Lecture 7: Software Design (Part II) Dr Valentina Plekhanova University of Sunderland, UK cs0vpl/SE-Com185.htm.

Lecture 7 Valentina Plekhanova 7

Low-level Design:Low-level Design:Basic ConstructsBasic Constructs All these 4 main methods of producing All these 4 main methods of producing

low-level design documents are based on 3 low-level design documents are based on 3 basic constructs:basic constructs:

sequence;sequence; selection;selection; iterationiteration (repetition) .(repetition) .

Page 8: Lecture 7: Software Design (Part II) Dr Valentina Plekhanova University of Sunderland, UK cs0vpl/SE-Com185.htm.

Lecture 7 Valentina Plekhanova 8

Low-level DesignLow-level Design Sequence Sequence is a linear progression where one is a linear progression where one

task is performed sequentially after task is performed sequentially after another. another.

Iteration: Iteration: WHILEWHILE is a loopis a loop with a simple with a simple conditional test at its beginning. conditional test at its beginning.

Selection:Selection: IF-THEN-ELSE IF-THEN-ELSE is a decisionis a decision in which a choice is made between two in which a choice is made between two alternative courses of action.alternative courses of action.

Page 9: Lecture 7: Software Design (Part II) Dr Valentina Plekhanova University of Sunderland, UK cs0vpl/SE-Com185.htm.

Lecture 7 Valentina Plekhanova 9

Low Level DesignLow Level Design Although these constructs are sufficient, it is Although these constructs are sufficient, it is

often useful to include three more constructs: often useful to include three more constructs: REPEAT-UNTILREPEAT-UNTIL is a loop with a simple is a loop with a simple

conditional test at the bottom. conditional test at the bottom. FORFOR is a special loop in which an index variable is a special loop in which an index variable

is automatically initialised, incremented, and is automatically initialised, incremented, and tested.tested.

CASECASE is a multiway branch (decision) based on is a multiway branch (decision) based on the value of an expression. the value of an expression. CASE CASE is a is a generalisation of generalisation of IF-THEN-ELSEIF-THEN-ELSE..

Page 10: Lecture 7: Software Design (Part II) Dr Valentina Plekhanova University of Sunderland, UK cs0vpl/SE-Com185.htm.

Lecture 7 Valentina Plekhanova 10

Basic SectionsBasic Sections There are usually 3 sections to all Low-There are usually 3 sections to all Low-

level designs: level designs: initialisationinitialisation, , processingprocessing, , and and terminationtermination..

Page 11: Lecture 7: Software Design (Part II) Dr Valentina Plekhanova University of Sunderland, UK cs0vpl/SE-Com185.htm.

Lecture 7 Valentina Plekhanova 11

Low Level Design:Low Level Design: InitialisationInitialisation

InitialisationInitialisation section includes opening files, reading the first record, and, if necessary, printing page and report headings.

Page 12: Lecture 7: Software Design (Part II) Dr Valentina Plekhanova University of Sunderland, UK cs0vpl/SE-Com185.htm.

Lecture 7 Valentina Plekhanova 12

Low Level Design:Low Level Design: ProcessingProcessing

ProcessingProcessing section includes DODO statements to show repetitive tasks that are performed on each record in the file – there are two ways to show this loop: DO DO while data remainswhile data remains

Processing stepsProcessing steps Read next recordRead next record

END DOEND DO

Page 13: Lecture 7: Software Design (Part II) Dr Valentina Plekhanova University of Sunderland, UK cs0vpl/SE-Com185.htm.

Lecture 7 Valentina Plekhanova 13

Low Level Design:Low Level Design: ProcessingProcessing

DODO until end-of-fileuntil end-of-file Processing stepsProcessing steps Read next recordRead next record

END DOEND DO

Page 14: Lecture 7: Software Design (Part II) Dr Valentina Plekhanova University of Sunderland, UK cs0vpl/SE-Com185.htm.

Lecture 7 Valentina Plekhanova 14

Low Level Design:Low Level Design: TerminationTermination TerminationTermination section includes what

happens at the very end of the program, such as closing the files and stopping the program.

Page 15: Lecture 7: Software Design (Part II) Dr Valentina Plekhanova University of Sunderland, UK cs0vpl/SE-Com185.htm.

Lecture 7 Valentina Plekhanova 15

What is Pseudocode?What is Pseudocode? PseudocodePseudocode 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 Instead, or in combination, we can use program flowcharts. program flowcharts.

Page 16: Lecture 7: Software Design (Part II) Dr Valentina Plekhanova University of Sunderland, UK cs0vpl/SE-Com185.htm.

Lecture 7 Valentina Plekhanova 16

Pseudocode: Important Notes Pseudocode: Important Notes Each textbook and each individual designer may Each textbook and each individual designer may

have their own personal style of pseudocode. have their own personal style of pseudocode. Pseudocode is not a rigorous notation, since it is Pseudocode is not a rigorous notation, since it is

read by other people, not by the computer. read by other people, not by the computer. There is no universal "standard" for the industry, There is no universal "standard" for the industry,

but for instructional purposes it is helpful if we but for instructional purposes it is helpful if we all follow a similar style.all follow a similar style.

Page 17: Lecture 7: Software Design (Part II) Dr Valentina Plekhanova University of Sunderland, UK cs0vpl/SE-Com185.htm.

Lecture 7 Valentina Plekhanova 17

Examples of Pseudocode: Examples of Pseudocode: Example 1Example 1 - - The problem

is to find the roots of a quadratic equation. Step 1Step 1 Prompt for and read the coefficients a, b, and c Step 2Step 2 If a = 0, do steps 3,4 Step 3Step 3 If b = 0 also, Error message: "no roots" and exit Step 4Step 4 Write single root -c/b and exit Step 5Step 5 Set d = b^2 - 4*a*c and if d < 0 Error message: "not real"

and exit Step 6Step 6 Set s = -(b + sqrt(d)*sign(b))/2 Step 7Step 7 Set x1 = s/a. Write this first (robust) root Step 8Step 8 Set x2 = c/s. Write this second (robust) root. Step 9Step 9 Set x3 = -(b - sqrt(d)*sign(b))/(2*a). Write this second (risky) root.

Page 18: Lecture 7: Software Design (Part II) Dr Valentina Plekhanova University of Sunderland, UK cs0vpl/SE-Com185.htm.

Lecture 7 Valentina Plekhanova 18

Example 2:Example 2: Pseudocode Pseudocode prompt the user to input the number of prompt the user to input the number of

days; days; user inputs the number of days; user inputs the number of days; multiply the number of days by 7 hours;multiply the number of days by 7 hours; display the total hours with an output display the total hours with an output

prompt.prompt.

Page 19: Lecture 7: Software Design (Part II) Dr Valentina Plekhanova University of Sunderland, UK cs0vpl/SE-Com185.htm.

Lecture 7 Valentina Plekhanova 19

Low-level Design: Low-level Design: Flow chartsFlow charts AA flowchartflowchart is a pictorial representation of is a pictorial representation of

the logic in a computer programthe logic in a computer program Based on the 3 basic constructs, Based on the 3 basic constructs, sequencesequence, ,

selectionselection andand iteration.iteration. In flow chart, certain shapes have special In flow chart, certain shapes have special

meaning, and arrows are used to connect meaning, and arrows are used to connect pieces of the flowchart. pieces of the flowchart.

Page 20: Lecture 7: Software Design (Part II) Dr Valentina Plekhanova University of Sunderland, UK cs0vpl/SE-Com185.htm.

Lecture 7 Valentina Plekhanova 20

Low-level Design: Low-level Design: Flow chartsFlow charts

Used to indicate the beginning (start) or end (stop) Used to indicate the beginning (start) or end (stop) of a computer program or subroutine.of a computer program or subroutine.

Used to indicate some type of input or output, Used to indicate some type of input or output, such as opening or closing Files.such as opening or closing Files.

Also known as a decision symbol, this is used to Also known as a decision symbol, this is used to indicate a decision to be made, choices based on indicate a decision to be made, choices based on logic – an “if” statementlogic – an “if” statement

Arrows are used to show the flow of the program Arrows are used to show the flow of the program – to show where the next item is located.– to show where the next item is located.

Page 21: Lecture 7: Software Design (Part II) Dr Valentina Plekhanova University of Sunderland, UK cs0vpl/SE-Com185.htm.

Lecture 7 Valentina Plekhanova 21

Some Examples:Some Examples: Pseudocodes & Flow ChartsPseudocodes & Flow Charts

Page 22: Lecture 7: Software Design (Part II) Dr Valentina Plekhanova University of Sunderland, UK cs0vpl/SE-Com185.htm.

Lecture 7 Valentina Plekhanova 22

Flow chart – SequenceFlow 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.

Task 1

Task 2

Page 23: Lecture 7: Software Design (Part II) Dr Valentina Plekhanova University of Sunderland, UK cs0vpl/SE-Com185.htm.

Lecture 7 Valentina Plekhanova 23

Flow chart – Selection: Flow chart – Selection: IF-THEN-ELSEIF-THEN-ELSE

Binary choice on a given Boolean condition is indicated by the use of four keywords: IFIF, THENTHEN, ELSEELSE, and ENDIFENDIF.

The general form is: IF IF condition THEN THEN sequence 1 ELSE ELSE sequence 2 END IFEND IF

The ELSEELSE keyword and "sequence 2" are optional. If the condition is true, sequence 1 is performed, otherwise sequence 2 is performed.

Condition

True False

Page 24: Lecture 7: Software Design (Part II) Dr Valentina Plekhanova University of Sunderland, UK cs0vpl/SE-Com185.htm.

Lecture 7 Valentina Plekhanova 24

Flow chart – Selection: Flow chart – Selection: IF-THEN-ELSEIF-THEN-ELSE ExampleExample

IFIF hours > 35 THEN THEN Display overtime message ELSEELSE Display regular time message END IFEND IF

Page 25: Lecture 7: Software Design (Part II) Dr Valentina Plekhanova University of Sunderland, UK cs0vpl/SE-Com185.htm.

Lecture 7 Valentina Plekhanova 25

Flow chart - Iteration (e.g. for, while)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, FORFOR and END FOREND FOR are used. Example:Example: The general form is:

FORFOR index = start to finish sequence END FOREND 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.

Page 26: Lecture 7: Software Design (Part II) Dr Valentina Plekhanova University of Sunderland, UK cs0vpl/SE-Com185.htm.

Lecture 7 Valentina Plekhanova 26

Flow chart - Iteration: WHILEFlow chart - Iteration: WHILE

The WHILEWHILE 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

WHILEWHILE and END WHILEEND WHILE. The general form is:

WHILEWHILE condition sequence END WHILEEND WHILE

Example:Example: WHILEWHILE number of days < 6 Compute hours as number of days * hours END WHILEEND WHILE

Page 27: Lecture 7: Software Design (Part II) Dr Valentina Plekhanova University of Sunderland, UK cs0vpl/SE-Com185.htm.

Lecture 7 Valentina Plekhanova 27

Flow chart - Iteration: WHILEFlow chart - Iteration: WHILE

Condition

True

False

The loop is entered only if the condition is true. The "sequencesequence" 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.

Page 28: Lecture 7: Software Design (Part II) Dr Valentina Plekhanova University of Sunderland, UK cs0vpl/SE-Com185.htm.

Lecture 7 Valentina Plekhanova 28

Low-level Design: Low-level Design: Important NotesImportant 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).

Page 29: Lecture 7: Software Design (Part II) Dr Valentina Plekhanova University of Sunderland, UK cs0vpl/SE-Com185.htm.

Lecture 7 Valentina Plekhanova 29

Week 8:Week 8: 24.04.2003-28.04.2003 24.04.2003-28.04.2003Project Control SessionProject Control Session Tutorial Time: 10 minutes for each Team Tutorial Time: 10 minutes for each Team Students will present project file, particularly

ScheduleSchedule, plus any project documentationdocumentation. 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.


Recommended