CSE100: Introductory Software Engineering - PowerPoint PPT Presentation

1 / 36
About This Presentation
Title:

CSE100: Introductory Software Engineering

Description:

Define the variable at the start of the module once only then use the ... The system variable value can't be changed. A module can't use the same variable name ... – PowerPoint PPT presentation

Number of Views:19
Avg rating:3.0/5.0
Slides: 37
Provided by: CS52
Category:

less

Transcript and Presenter's Notes

Title: CSE100: Introductory Software Engineering


1
CSE100 Introductory Software Engineering
  • Lecture 11 Implementation
  • Module Communication Flowcharts

2
Small Module Benefits
  • We considered earlier how big/small a module of
    code should be
  • e.g. 1 page?
  • e.g. 7 statements?
  • We said you could have
  • A few large modules with a few links between them
  • Many small modules with many links between them
  • A mix of the 2

3
If small
  • software is easier to write
  • software can be re-used more easily because
  • a module should fulfill only 1 task
  • modules must be able to communicate
  • we call this interfacing with other modules

4
ATM Example
  • Think back to when we looked at the use cases for
    the ATM (cash machine) scenario
  • When withdrawing money, there could be just 2
    functions to perform
  • Check not overdrawn when cash withdrawn
  • Withdraw the money

5
Module Chart and Module Calls
accountNo amount
reply
accountWithdrawal
accountNo
accountNo
amount
amount
overdrawn
withdrawCash
checkOverdrawn
6
Module Calls
  • Module accountWithdrawal (accountNo, amount)
  • overdrawn checkOverdrawn(accountNo, amount)
  • If overdrawn is true
  • return fail (reply false)
  • exit
  • withdrawCash(accountNo, amount)
  • return success (reply true)
  • Module end

7
The Function Table
Function accountWithdrawal
Parameters string accountNo, integer amount
Return Type boolean Description
Check the bank balance of accountNo with
amount to be withdrawn (amount) if overdrawn
confirm overdrawn (fail) otherwise withdraw
cash (success)
8
Pseudocode
  • Pseudocode defines the structure of the code
  • Defines a problem procedurally using constructs
  • Sequence
  • Selection
  • Iteration
  • Very close to actual programming code

9
Flowcharts
  • A graphical presentation
  • Concentrates upon the logical flow of the code
    NOT its structure
  • Represents procedural code well for
  • Sequence
  • Selection
  • Cant directly represent iteration (loops)

10
Flowchart Use
  • Several uses
  • Used to show slide order in a prototype or
    storyboard analysis
  • Used to show logical flow of code in a
    specification
  • Used to identify test paths in a program.

11
Flowchart Symbols
Start or end
Process
Input or output
Decision
Flow line
12
Start
Have items?
Water in Kettle?
Turn on kettle
Yes
Yes
Is water boiled?
No
No
Yes
Fill kettle with water
Find kettle, water, mug, spoon, coffee granules,
sugar
No
Make a cup of coffee
End

13
Sequence
Any normal processing step
Increment Index
Increment Index
2 processes together in sequence
Sum Sum markindex
14
Selection
Sum ? Sum mark
A sequence action followed by a Selection.
Determines 1 of 2 Paths to take. (likely IF
statement in Java, VB, C)
Yes
Sum lt 40
No
15
Iteration
  • looping statement
  • loop index 1 to numberOfStudents step 1
  • We need to define for the flow chart
  • The initial value of loop control (index)
  • The terminating condition
  • The increment for loop control

16
Iteration in Flowcharts
Index ? 1
Initialise loop control
index numberOf Students
gt
Check for Terminating Condition
(Exit Loop)
lt
Loop statements
17
Iteration in Flowcharts
Index ? 1
Initialise loop control
index numberOf Students
gt
Check for terminating Condition
(Exit Loop)
lt
Loop statements
Increment (or decrement) the loop control
Increment index
18
Nassi-SchneidermannDiagrams
  • Like pseudocode as they identify the code
    structure
  • Like flowcharts because they are diagrams
  • They are more amenable for computerisation than
    flowcharts.

19
Nassi-SchneidermannDiagrams - Iteration
Statement 1 Loop A Control Statement2 Stateme
nt 3 Loop B Control Statement 4 Statement
5 End Loop B statement 6 End Loop A
Indented Loop Box
A Loop Box Within a Loop Box
20
NASSI Conditional Statements
If Statement
Y
N
Statement 1 Statement 2 (Performed when if
statement is TRUE)
Statement 3 (Performed when if Statement is
FALSE)
Continue from here when either Y or N
branches are completed.
21
NASSI If within a Loop
Loop
If
N
Y
Loop End
22
  • Time for Break/Change of tasks!

23
Improving the Quality of Software
24
  • Good software benefits
  • The benefits of replacing literals with variables
  • Changing functionality with control data
  • Separating code and data to make software more
    flexible and reusable
  • Where best to source control data

25
Literals
  • Dont use literals in code everything changes
    sooner or later so prepare for change
  • Set variables in the initialisation phase of the
    module
  • e.g. If the assessment regime used by a module
    has 4 assessments you wont have long to wait
    until someone wants to change it

25
26
Replacing Literals with Variables
  • Better to use a variable e.g. numAssessments
  • The variable can be initialised at the start of
    the module
  • For any programmer who needs to modify the
    program
  • For loopIndex 1 to numAssessments
  • is more flexible than
  • For loopIndex 1 to 4

26
27
Initialising Variablesat the Start of Modules
  • A variable name can identify the purpose of the
    value, a literal cannot
  • Define the variable at the start of the module
    once only then use the variable throughout the
    module
  • The purpose of a literal value is easy to forget
    or hard to understand
  • Instead of message literals embedded in the code,
    set up a table of messages that can be easily
    changed.

27
28
Using a Message Table instead of Message Literals
  • Instead of
  • messageBox ? invalid mark
  • Use
  • messageBox ? message1 from

Message Table Message1 invalid
mark Message2 array error Message3 mark
update error Message4 mark out of bounds
28
29
System Variables
  • Many programming languages and operating systems
    make available system variables
  • Available for use by all programs
  • The most frequently used system variable is
    todays date
  • The data must be referred to by the same name in
    all programs (e.g. sysdate)
  • You must use the correct name
  • You cant use that name for your own data

29
30
System Variables
The system variable value cant be changed. A
module cant use the same variable name to
re-assign values for a different purpose
Global Data
Module 1
sysdate
Module 2
Module 3
30
31
Using the same Data in several Modules
  • What if the same data is used in many different
    modules in a program?
  • e.g. What if income tax rates are used in several
    different places in a payroll program?
  • Better to have a special module to initialise
    important variables

31
32
Using the Same DataAcross Large Programs
Main
numAssessments ? 4 Set here
Print Transcript
Process Student Marks
Initialise Variables
numAssessments used here
Calculate final Mark
Read Student Details
32
33
Important Data
  • Data such as numAssessments may control the way a
    program functions
  • Setting the values of important variables in an
    initialisation module may not be considered very
    flexible
  • Input important values as input to a program?
  • Important data might be stored and accessed from
    a control file
  • Users can modify data on the control file

33
34
Key Data Stored on File
Main
Initialisation- read variables from file
Print Transcript
Process Student Marks
numAssessments used here
Calculate final Mark
Read Student Details
34
35
Separating Data and Code
  • Use of variables instead of literals makes
    programs easier to modify
  • The use of variables separate code from data
  • What a program can do (its functionality) can be
    increased by using variables

35
36
To Recap
  • As a rule try to remove the need to change code
  • software control data should be stored in one
    place (initialisation module, file, database)
  • Ensure the impact of change on software code is
    minimised
  • When sharing the same data between modules, there
    is some loss in efficiency but not significant

36
Write a Comment
User Comments (0)
About PowerShow.com