1 cse1301 computer programming lecture 24: software engineering
TRANSCRIPT
2
Topics
• Thus far in CSE1301 • Tools and techniques
– Structure Charts– Dataflow Diagrams– Prototyping
• Structured design– Modularity– Coupling– Cohesion
Reading: Brookshear: Chapter 6
3
Thus far in CSE1301…• Computer Systems
– Overview of what computers are made of.
• Components of an Algorithm– Values, Variables, Instructions, Sequence, Selection,
Iteration, Procedure, Documentation
• The C Language– Operations, Identifiers, Types, Input/Output, Files, Arrays,
Pointers, Functions, Structs, etc.
– Vocabulary: main, int, float, scanf, printf, if, while, for, fopen, struct, etc
But we have implemented small programs only!
4
Software Engineering• Essential to have a process for large projects• Structured development of software systems
– Examples: software for banking, stock exchange, space probe control, toll charge, operating system, games
• Tools and Techniques– Structured process rather than trial-and-error.– Important goal: eliminate errors.
• “Engineering”– Zero tolerance to error.– Pre-fabricated components.– Re-usable components.
5
• Tasks– project planning (cost, schedule, personnel)– project management – documentation – prototyping and simulation– interface design– programming– testing
• Computer-Aided Software Engineering (CASE) Tools
Software Engineering
6
Components of the Software Development Process:
Define the problem clearlyAnalyse the problem
Design an algorithmtop-down / bottom-up design
Document the system
Code (Implement) the algorithmTest the code
Recall:
7
Development Approach:Water-Fall Model (Old)
Analysis Design Implement Test
• Requires that each stage be totally completed before beginning next stage.
8
Development Approach:Incremental Model
Analysis Design Implement Test
• Increments from simplified version with limited functionality to complete system.
• At each stage: prototype.
9
Prototyping
• Construction of simplified version of parts of the proposed system that can be analysed before further development.
• Types of items that can be prototyped:– screen and report format, database and file
structures, system protocols, etc.
10
Modularity• Top-down analysis and design.
• Break problem down into manageable sub-problems (or modules)
Example:
Hold a party
Send invites
Prepare food
Prepare music
Select people in address bookContact invited people
Decide on menuGo shoppingCook
Find songs on cd
Create a new cd with selections…
11
Modularity
• Top-down analysis and design.
• Break problem down into manageable sub-problems (or modules)
Example: Hold a party
Prepare food
Decide on menu Go shopping
Prepare music
Cook
Create shopping list Drive to shops Buy groceries …
12
Golden Rule #1
Design Top-Down,
but always build Bottom-Up.
• Code and test the simplest components first.• Test each component before using them to make sure they work• Then use those components to build more complex
components.
13
Structure Chart
• Pictorial representation of a modular structure– each module represented by a rectangle– arrows represent dependencies between modules
Hold a party
Prepare food
Decide on menu Go shopping
Prepare music
Cook
Create shopping list Drive to shops Buy groceries …
14
Coupling
• Links and dependencies between modules
• Control coupling: – when one module passes control to another– Examples: function call, return
• Data coupling: – sharing of data between modules.– Examples: function parameters, return values
15
ExampleStructure chart with labels showing data coupling
goShopping ( place, menu ){ list = createGroceryList( menu ) driveTo (place ) buyItems ( list )} goShopping
createGroceryList buyItemsdriveTo
plac
e
men
u
list
men
u
list p
lace
…
16
Notes on Coupling
• Aim: maximize module independence = minimize coupling.
• Use of global variables (not constants) is a form of implicit data coupling: dangerous!– It is NOT recommended to have global variables
in your program.
17
Notes on Coupling
• How is control coupling represented in code? – Function call: When a function is called, control is
passed to that function.– Function return: When the code in a function has
been executed, control is returned to the code that called the function.
• How is data coupling represented in code?– Data sent to a function via parameters.– Data returned from function using "return".– Data modified in function using a pointer
parameter.
18
Cohesion
• Internal binding within function, i.e. degree of relatedness of a module’s internal parts.
• Logical cohesion– Internal elements perform activities that are
logically similar. (Eg. I/O function)
• Functional cohesion– all parts are geared towards single activity
• Aim: high intra-module cohesion
19
Example 1contact ( company , message , mode ){ if mode is by fax { sendFax ( company , message) } else if mode is by email { sendEmail ( company , message) }}
Cohesive.
20
Example 2
Not cohesive.
contact ( company , message , mode ){ if mode is by fax { sendFax ( company , message) } else if mode is by email { sendEmail ( company , message) } printAddressBook ( )}
21
Golden Rule #2
Modules in a well-structued program are highly cohesive
and loosely coupled.
• The size of the data coupling corresponds roughly to the level of the module in the hierarchy.
22
Dataflow Diagrams (DFD)
• Pictorial representation of data paths:
– origin (source)
– destination (sink, storage)
– processing points (location of data manipulation, modules)
23
Dataflow diagram showing data pathsR
ecip
e B
oo
ks
Menu
Recipes
Shop
List Buy Items
List
Drive to Shops
Prepare Menu
Prepare Gocery List
Name, Address
Shop address lis
t
Address
Cost
24
Arrows: Data Paths R
ecip
e B
oo
ks
Menu
Recipes
Shop
List Buy Items
List
Drive to Shops
Prepare Menu
Prepare Gocery List
Name, Address
Shop address lis
t
Address
Cost
25Boxes: Data Sources and Sinks
Rec
ipe
Bo
oks
Menu
Recipes
Shop
List Buy Items
List
Drive to Shops
Prepare Menu
Prepare Gocery List
Name, Address
Shop address lis
t
Address
Cost
26
Circles (Bubbles): Processing Points R
ecip
e B
oo
ks
Menu
Recipes
Shop
List Buy Items
List
Drive to Shops
Prepare Menu
Prepare Gocery List
Name, Address
Shop address lis
t
Address
Cost
27
Heavy Straight Lines: Data StorageR
ecip
e B
oo
ks
Menu
Recipes
Shop
List Buy Items
List
Drive to Shops
Prepare Menu
Prepare Gocery List
Name, Address
Shop address lis
t
Address
Cost
28
You (the Processor) are not included in the diagram!
Rec
ipe
Bo
oks
Menu
Recipes
Shop
List Buy Items
List
Drive to Shops
Prepare Menu
Prepare Gocery List
Name, Address
Shop address lis
t
Address
Cost
29
Dataflow diagrams (DFD)
• Emphasise the data (information) to flow through system.
(rather than procedures to be executed)
• By following data paths, discover where data units are merged, split, or altered.