Beruflich Dokumente
Kultur Dokumente
Topic 5:
Software Design
Your Name: _____________________
Computer Science & Engineering Department
The Chinese University of Hong Kong
Chinese University, CSE Dept.
Software Engineering / 5 - 1
Prelude
Software design should be based on s/w engineering
principles
Rigor and formality
Appropriate notations for design
Generality
Product family
Chinese University, CSE Dept.
Software Engineering / 5 - 2
Prelude
Software design should be based on s/w engineering
principles
Rigor and formality
Appropriate notations for design
Generality
Product family
Chinese University, CSE Dept.
Software Engineering / 5 - 3
Prelude
High quality design
modular structure
decomposition criteria
Software Engineering / 5 - 4
Top-down design
Chinese University, CSE Dept.
Bottom-up design
Software Engineering / 5 - 5
Description of
a)functions of each module
=> ____-module
b)interfaces between modules => ____-module
the software structure (architecture)
Chinese University, CSE Dept.
Software Engineering / 5 - 6
M M
M
D ecom pose
1
2
3
Software Engineering / 5 - 7
What Changes?
Change of algorithms
to improve efficiency, generality
e.g. sorting algorithm (____________ ____________)
Software Engineering / 5 - 8
What Changes?
Change of algorithms
to improve efficiency, generality
e.g. sorting algorithm (____________ ____________)
Software Engineering / 5 - 9
Software Engineering / 5 - 10
Software Engineering / 5 - 11
Product Families
A set of different versions of a program, due to
different h/w or s/w
different environment with different requirements
on performance or resource consumption
system evolution due to new requirements or
quality improvement
Usually with the same basic set of functional
requirements
Software Engineering / 5 - 12
Product Families
The solution:
minimize the cost of changing design decisions
Necessary tools to manage product families:
____________________________ tools
Software Engineering / 5 - 13
Sequential Completion:
A Graphical View
Requirements
Requirements
Requirements
1
____________
2
2
__________
Version 1
Version 1
3
3
4
4
4
Version 1
Version 2
Chinese University, CSE Dept.
Version 2
5
3
6
7
Version 3
Software Engineering / 5 - 14
Modularization Techniques
1) Architecture design (overall structure)
2) Detailed design (design of each module by
information hiding)
Software Engineering / 5 - 15
Software Engineering / 5 - 16
Software Engineering / 5 - 17
ii.
contain _______________: Mi r+ Mj
iff Mi r Mj or Mk Mi r Mk and Mk r+ Mj
iii. ________(________):if Mi r+ Mj (Mj r+ Mi)
Software Engineering / 5 - 18
M1
M3
M2
M1,2
M1,1
M1,2,1
M4
M6
a)
M1,2,1,1
M1,3
M1,2,2
M2
M3
M4
Level
___
___
___
___
___
Software Engineering / 5 - 19
Software Engineering / 5 - 20
Q:
Is
_________________
__________________
Chinese University, CSE Dept.
equivalent
to
relation?
Software Engineering / 5 - 21
write
read
C: _________________
Fortran: _____________
General: __________Variables
Chinese University, CSE Dept.
Software Engineering / 5 - 22
Software Engineering / 5 - 23
USES Relation
USES relation is static, i.e., independent of the
execution of the s/w:
in Module M:
if cond then proc1 else proc2
in M1
in M2
USES
Software Engineering / 5 - 24
USES Relation
For a good design, USES relation should be hierarchy
i.
easy to understand
separation of concerns => used components first, then their
clients
Software Engineering / 5 - 25
Software Engineering / 5 - 26
M3
M3
Software Engineering / 5 - 27
IS_COMPONENT_OF Relation
Let S be a set of modules M1,M2,,Mn
for any Mi,Mj S, Mi IS_COMPONENT_OF Mj means
Mj is realized by several modules, one of which being M i
Mj COMPRISES Mi
Software Engineering / 5 - 28
M
7
M2
M
5
M3
M
6
M1
M4
M
7
M1
(IS_COMPONENT_OF)
M2
M3
M
5
M4
M
6
(COMPRISES)
M7 is component of _____
_______ comprises M7
_______________ implements M2
Chinese University, CSE Dept.
M2 is composed of ___________________
Software Engineering / 5 - 29
Software Engineering / 5 - 30
Is-composed-of
M3
M3,1
M1
M3,2
M3,3
M2
Design
Decision 1
Version 1
M5
M6
_______
M4
Design
Decision 2
Uses
M2
_______
_______
M4
M7
Version 2
M1
Uses
M2
M3
M1
_______
_______
M4
_______
Software Engineering / 5 - 31
______________
Structure chart level
Software Engineering / 5 - 32
Software Engineering / 5 - 33
6. ______ cohesion
______ coupling
Software Engineering / 5 - 34
Software Engineering / 5 - 35
Software Engineering / 5 - 36
Software Engineering / 5 - 37
Software Engineering / 5 - 38
Software Engineering / 5 - 39
Typical Secrets
1. The algorithm for carrying out some operation, e.g.
algorithms for sorting routine
2. The representation of some data structure, e.g.
abstract data type
Software Engineering / 5 - 40
Software Engineering / 5 - 41
Software Engineering / 5 - 42
Software Engineering / 5 - 43
formal in syntax
informal in semantics
1. TDN (Textual Design Notation)
2. GDN (Graphical Design Notation)
Software Engineering / 5 - 44
____________
__________ relation
__________
implementation
__________ relation
end
Software Engineering / 5 - 45
______________________________
Implementation
______________________________
is composed of R, T
end X
Chinese University, CSE Dept.
Software Engineering / 5 - 46
Software Engineering / 5 - 47
end R
module T
uses Y, Z, R
exports var A: integer;
implementation
end T
Chinese University, CSE Dept.
Software Engineering / 5 - 48
X exports _____________;
only ________ are imported here;
referred as ___________.
XX resources ____________.
Software Engineering / 5 - 49
TDN
A TDN design takes some time to
comprehend
TDN can provide various levels of details
e.g., ______________ in great detail
Software Engineering / 5 - 50
Software Engineering / 5 - 51
Module
R
Module
T
C
Module Z
Software Engineering / 5 - 52
Module
T
Module Z
Software Engineering / 5 - 53
Module M
Module L
Module N
Module M
Module M
Module R
Module S
IS_COMPONENT_OF what?
_________________
IS_COMPOSED_OF what?
_________________
Exports what?
_________________
Module M
USES what?
_______ (which exports _______ )
Module H
Module F
Module G
K
Software Engineering / 5 - 54
Software Engineering / 5 - 55
Categories of Modules
1) Procedural abstractions
purpose: to encapsulate an ____________
e.g.: sorting module, fast Fourier transform
module
2) Libraries
purpose: to group together related
___________________________
e.g.:
mathematical routines
graphical routines
Chinese University, CSE Dept.
Software Engineering / 5 - 56
Categories of Modules
3) Common pool of data
purpose: to share _______ among several
modules
e.g.: system configuration constants group
note:
Software Engineering / 5 - 57
Categories of Modules
4) Abstract objects
purpose: to hide the details of data __________
(change of data structures is _________ of cost for
total software maintenance)
e.g.: a symbol-table
note: exhibit a state
Software Engineering / 5 - 58
Categories of Modules
5) Abstract data type
note:
i) no state
ii) can generate many instances (___________)
Software Engineering / 5 - 59
Software Engineering / 5 - 60
Software Engineering / 5 - 61
Software Engineering / 5 - 63
Software Engineering / 5 - 64
Software Generator
yacc - compiler generator
user interface generator
executable specification language
Software Engineering / 5 - 65
Stepwise Refinement
a popular method for describing the logical
structure of a given algorithm, implemented by
a single module
stepwise refinement is an effective way of
describing a solution after it has been partially
obtained (software engineering principle:
_______________)
Software Engineering / 5 - 66
Software Engineering / 5 - 67
Step 2
let n be the length of the array a to be sorted;
i := 1 ;
while i < n loop
j := n;
while j > i loop
if a(i) > a(j) then
interchange the elements at
positions j and i ;
end if;
j := j - 1;
end loop;
i := i + 1;
end loop;
Chinese University, CSE Dept.
Software Engineering / 5 - 68
Step 3
let n be the length of the array a to be
sorted;
i := 1 ;
while i < n loop
j := n;
while j > i loop
if a(i) > a(j) then
x := a(i);
a(i) := a(j);
a(j) := x;
end if;
j := j - 1;
end loop;
i := i + 1;
Software Engineering / 5 - 69
Chinese University, CSE
Dept.loop;
end
Stepwise Refinement
P
P
C
P
2,1,1
Step 0
P
Step 1
not C
[ If C1 then P2,1,1
Else P2,1,2]
Step 2
2,1,2
Step N
Software Engineering / 5 - 70
Stepwise Refinement
It is a method that works in the small, but fails
in the large. Here are the reasons:
1. sub-problems tend to be analyzed in isolation,
reducing ______________
2. No attention is paid to _______________
3. No attention is paid to _______________
4. The ________ function may not exist
5. A premature commitment to the ____________
structures
Chinese University, CSE Dept.
Software Engineering / 5 - 71
information hiding
bottom-up design
combining both
yo-yo design
Software Engineering / 5 - 72
Handling Anomalies
To achieve reliable solutions
Systematic design approach
Rigorous and disciplined implementation
Software Engineering / 5 - 73
Handling Anomalies
Anomalous if a module fails to provide a
service as expected and specified in its
interface
_________ to be associated with a service,
denoting the anomalies that may occur while that
service is being performed
Software Engineering / 5 - 74
Handling Anomalies
Defensive design requires that upon entering
an anomalous state, the module should signal
the anomaly by raising an exception to the
client
The server module terminates the service
after _________ an exception; the client
responds by suitably ________ the exception
Software Engineering / 5 - 75
Software Engineering / 5 - 76
Ms client
Ms client
B;
_____ the
exception
C;
______ an
exception
__
M
__
M:
______ an
exception
__
Ms server
Chinese University, CSE Dept.
Ms server
Software Engineering / 5 - 77
Module M
module M
exports . . .
procedure P (X: INTEGER; . . .)
raises X_NON_NEGATIVE_EXPECTED,
INTEGER_OVERFLOW;
X is to b e positive; if not, exception
X_NON_NEGATIVE_EXPECTED is raised;
INTEGER_OVERFLOW is raised if internal
computation of P generates an overflow
end M
.
.
.
Software Engineering / 5 - 78
Module L
module L
uses M imports P (X: INTEGER; . .)
.)
exports . . .;
procedure R ( . . .)
raises INTEGER_OVERFLOW;
.
.
.
implementation
If INTEGER_OVERFLOW is raised when P is invoked, the
exception is propagated
end L
.
.
.
Software Engineering / 5 - 79
Concurrent Software
The case of a module defining shared data
E.g., abstract object BUFFER
module QUEUE_OF_CHAR is GENERIC_FIFO_QUEUE
(CHAR)
BUFFER : QUEUE_OF_CHAR.QUEUE
with operations
Software Engineering / 5 - 80
Software Engineering / 5 - 81
Enforcing Synchronization
Ensure that operations on buffer are executed
in mutual exclusion
Ensure that operations such as
if QUEUE_OF_CHAR.NOT_FULL (BUFFER) then
QUEUE_OF_CHAR.PUT (X, BUFFER);
end if;
Software Engineering / 5 - 82
Monitors
Abstract objects used in a ____________
environment
Available in the Java programming language
Software Engineering / 5 - 83
Monitors: an Example
concurrent module CHAR_BUFFER
This is a monitor, i.e., an abstract object module in a
concurrent environment
uses . . .
exports
procedure PUT (C : in CHAR) requires NOT_FULL;
procedure GET (C: out CHAR) requires NOT_EMPTY;
NOT_EMPTY and NOT_FULL are hidden Boolean
functions yielding TRUE if the buffer is not empty and not
full, respectively. They are not exported as operations,
because their purpose is only to delay the calls to PUT and
GET if they are issued when the buffer is in a state where it
cannot accept them
.
.
.
end CHAR_BUFFER
Chinese University, CSE Dept.
Software Engineering / 5 - 84
Comments on Monitors
Monitor operations are assumed to be
executed in _________________
A requires clause may be associated with an
operation
it is automatically checked when operation is
called
if the result is false, the current process is
suspended until it becomes true (at that stage it
becomes eligible for resumption)
Software Engineering / 5 - 85
Software Engineering / 5 - 86
Software Engineering / 5 - 87
A Guardian Task
loop
select
when NOT_FULL
accept PUT (C: in CHAR);
This is the body of PUT; the client calls it as if it
were a normal procedure
end ;
or
when NOT_EMPTY
accept GET (C: out CHAR);
This is the body of GET; the client calls it as if it
were a normal procedure
end ;
end select ;
end loop ;
Chinese University, CSE Dept.
Software Engineering / 5 - 88
conversely, A generalizes B
A is a superclass of B
B is a subclass of A
Chinese University, CSE Dept.
Software Engineering / 5 - 89
M1 INHERITS_FROM M2
Software Engineering / 5 - 90
Software Engineering / 5 - 91
Software Engineering / 5 - 92
NAME
AGE
WHERE
uses
exports
Module EMPLOYEE
Module SITE
_____________________
DO_THIS
_________
Module
Module
ADMINSTRATIVE
TECHNICAL
STAFF
STAFF
________
GET_SKILL
DEF_SKILL
________
Module
Module
FOLDER
SKILL
Software Engineering / 5 - 93
Properties of Inheritance
Inheritance allows a hierarchical classification
scheme for abstract data types through
generalization-specialization relations
distinguish commonalities and differences among
a (potential) set of abstract objects
commonalities are factored out in a ________
class
variations are singled out in the ___________
classes
Chinese University, CSE Dept.
Software Engineering / 5 - 94
Properties of Inheritance
Inheritance improves reusability - ________
class
Inheritance is a way of building software
______________
Disadvantage of inheritance
Software Engineering / 5 - 95
Properties of Inheritance
A subclass defines a subtype
subtype is substitutable for parent type
Polymorphism
a variable referring to type A can refer to an object of
type B if B is a subclass of A
Dynamic binding
the method invoked through a reference depends on
the type of the object associated with the reference
at runtime
Chinese University, CSE Dept.
Software Engineering / 5 - 96
Software Engineering / 5 - 97
Software Engineering / 5 - 98
ADMINISTRATIVE_STAFF
TECHNICAL_STAFF
Software Engineering / 5 - 99
UML Associations
Associations are relations that the
implementation is required to support
Can have multiplicity constraints
TECHNICAL
_STAFF
PROJECT
project_member
1..*
manages
MANAGER
1
Chinese University, CSE Dept.
UML Aggregation
Defines a PART_OF relation
Differs from IS_COMPOSED_OF
Here TRANGLE has its own methods
It implicitly uses POINT to define
its data attributes
TRIANGLE
1
3
POINT
More on UML
UML evolves from TDN/GDN
USES relationship is refined with semantically richer relationship: inheritance,
association, and aggregation
If class B inherits from class A, B USES A => ___________ USES _________
Association between classes implicitly define USES relation => ___________ USES
____________
If B aggregates A, B USES A => __________ USES __________
package_name
Class 1
Class 3
Class 2
Chinese University, CSE Dept.
Software Architecture
Describes overall system organization and
structure in terms of its major constituents and
their interactions
Standard architectures can be identified
pipeline
blackboard
event based (publish-subscribe)
Standard Architectures
Pipeline
Example:
_________________
Blackboard
Example: ____________ ,
_________________
event based
Example: _______________
_______________________
Model (store
data, e.g., text)
Chinese University, CSE Dept.
Webbrowser
(client)
to three tiered
Userinterface
(client)
Requests
for service
(database)
Requests
for service
(pages)
Decode
service
request
(2nd tier)
Webserver
(server)
Application
server
(databse)
/****************************************
* MODULE TO FIND INTERSECTION OF TWO LINES
Control structures
Algorithms
Data structures
General guidelines
Control Structures
Using Fundamental Constructs
Main ingredients for structured programs:
1.
______________e.g.,___________________
2.
______________e.g.,___________________
3.
______________e.g.,___________________
Control Structures
________
________
Control Structures
____________
__________
____________
OR
Control Structures
Top-down Flow
Programs should be readable from the top down
Use of Submodules
Follow the design to build submodules (functions,
procedures, macros) for elemental functions
Build general submodules for ____________
Explain _________ of submodules, but not their
details
Algorithms
Program design often specifies a class of
algorithms to be used
Efficiency of code should consider
1.
2.
3.
4.
5.
____________ of code
time to ______ the code
time to ______ the code
time for users to ___________ the code
time to ______ the code, if necessary
Data Structures
Keeping the Program Simple. Restructuring data
can simplify a program.
Keep It Simple and Straightforward: _________
General Guidelines
Using Pseudocode
Revising and Rewriting Instead of Patching
Program 1
TAX = 0.
IF TAXABLE_INCOME = 0, GO TO EXIT
IF TAXABLE_INCOME > 10,000, TAX = TAX + 1000.
ELSE TAX = TAX + 0.10 * TAXABLE_INCOME
GO TO EXIT
IF TAXABLE_INCOME > 20,000, TAX = TAX + 1200.
ELSE TAX = TAX + 0.12*(TAXABLE_INCOME 10000.)
GO TO EXIT
IF TAXABLE_INCOME > 30,000, TAX = TAX + 1500.
ELSE TAX = TAX + 0.15*(TAXABLE_INCOME 20000.)
GO TO EXIT
IF TAXABLE_INCOME < 40,000, TAX = TAX + 0.18*(TAXABLE_INCOME 30000.)
GO TO EXIT
ELSE TAX=TAX+1800.+0.20*(TAXABLE_INCOME40000.)
EXIT: END
Program 2
Build a Sample Tax Table First:
Bracket Base
Percent
0 0
10
10,000 1000
12
20,000 2200
15
30,000 3700
18
40,000 5500
20
The Program:
LEVEL = 1
FOR I = 1 TO 4 DO
IF ______________________________
THEN ___________________________
TAX = ______________________________________________________
Sample
______
______
______
______
______
______
Documenting Data
_________________________________
Chinese University, CSE Dept.
Topic 5 Conclusion
Software design activities and modularization techniques
Overall structure design
Hierarchical relations, uses relation, is_component_of relation
Interface and information hiding
Detailed design
TDN, GDN
Category of modules
Stepwise refinement
Handling anomalies
Inheritance
UML in software design
Program implementation techniques