Professional Documents
Culture Documents
3100 Topic4
3100 Topic4
3100 Topic4
Topic 4:
Software Specification
Your Name: _____________________
Computer Science & Engineering Department
The Chinese University of Hong Kong
Chinese University, CSE Dept.
Software Engineering / 4 - 1
Prelude on Specification
A specification is a precise statement of the
requirements that a system must satisfy
the term specification is used at different
stages of system development
(i) requirement specification
(ii) design specification
(iii) module specification
Chinese University, CSE Dept.
Software Engineering / 4 - 2
Specification
A broad term that means _____________
Used at different stages of software
development for different purposes
Generally, a statement of agreement
(_____________) between
producer and consumer of a service
implementer and user
Software Engineering / 4 - 3
What Is A Specification?
A specification at some level states the
requirements for the implementation at a
lower level
It is viewed as a definition of ________ the
implementation must provide, not _________
The distinction between what and how is
not sharp.
e.g., a simple way to describe what is just to give
an example of how
e.g., display of time: hour + : + minute
1 2 digit 12
Chinese University, CSE Dept.
0 2 digit 59
Software Engineering / 4 - 4
Uses of Specification
Statement of ______________ requirements
major failures occur because of misunderstandings
between the producer and the user
A users needs are sometimes not clearly understood
by the developer
Sometimes, even the user has no clear idea of what
exactly the desired product is
"The hardest single part of building a software system
is deciding precisely what to build" (F. Brooks)
Software Engineering / 4 - 5
Software Engineering / 4 - 6
Software Engineering / 4 - 7
Software Engineering / 4 - 8
Specification Qualities
(1) Spec should be clear, unambiguous, and
understandable
pictures are better, if possible (e.g. Galileo)
informal spec, written in natural languages
(English), are likely to hide subtle ambiguities
Two examples
(i) select in Microsoft Word 4.0
(ii) message triplication
Software Engineering / 4 - 9
Spec Examples
(i) A select command in a word processor
___________
___________
not sure if
possible or not
from the spec
Software Engineering / 4 - 10
Spec Examples
(ii) A mission-critical project
The message must be triplicated. The three
copies must be forwarded through three
different physical channels. The receiver
accepts the message on the basis of a twoout-of-three voting policy.
When? As soon as two identical messages
are received or has to wait for 3
messages?
Chinese University, CSE Dept.
Software Engineering / 4 - 11
Specification Qualities
(2) Spec should be ________________
An example: word processing for text
English spec:
The whole text should be kept in lines of equal length,
with the length specified by the user
Unless the user gives an explicit hyphenation command,
a carriage return should occur only at the end of a word
Software Engineering / 4 - 12
Specification Qualities
(3) Spec should be ________________________
internally complete (self-contained)
define all new concept or terminology it uses
glossary helpful for this purpose
Software Engineering / 4 - 13
Specification Qualities
(4) Spec should be __________________
Referring to the specification process
start from a sketchy document and progressively add
details
Software Engineering / 4 - 14
Software Engineering / 4 - 15
Software Engineering / 4 - 16
Software Engineering / 4 - 17
p2
p1
ap1 + ap2 = bp1 + bp2
(x, y)
x
Software Engineering / 4 - 18
Descriptive spec:
The result of sorting a is an array b which is a permutation of a and
is sorted.
Feature: _____________________________________________
Chinese University, CSE Dept.
Software Engineering / 4 - 19
Software Engineering / 4 - 20
Verification of Specs
specs must be verified prior to design and implementation
two general techniques:
(1) observe the dynamic behavior of the specified system to check its
correctness (___________________ spec)
(2) analyze the properties of the specified system that can be deduced
from the spec (_____________________ spec)
Software Engineering / 4 - 21
Operational Specifications
A)
B)
C)
Software Engineering / 4 - 22
Software Engineering / 4 - 23
Software Engineering / 4 - 24
specifies evaluation of
(a + b) * (c + a * d)
Figure 4.1
Software Engineering / 4 - 25
Output
1
2
Input n
information
...
system
...
Output
Output
1
2
m
Software Engineering / 4 - 26
H
I
A3
J
A4
A1
K
A2
K2
S
N
A6
P
A5
B2
K3
K1
B1
Ag
A7
B3
B4
K4
Software Engineering / 4 - 27
Book request
by the user
Shelves
Author
Book
List of Authors
Get a book
Title
Book title;
user name
List of titles
Title
Search by
topics
List of topics
Topic
Topic
Topic request
by the user
Book
reception
List of titles
referring to the topic
Display of
the list of titles
Figure 4.2
Software Engineering / 4 - 28
Shelves
Author
Get
the book
Book
List of Authors
Find
book
position
Title
Book
rec eption
List of titles
Title and author
of requested book;
name of the user
Book request
by the user
Chinese University, CSE Dept.
<shelf#, book#>
Book title;
user name
Figure 4.3
Software Engineering / 4 - 29
Software Engineering / 4 - 30
D
F
Figure 4.4
Software Engineering / 4 - 31
Figure 4.5
Possible interpretations:
(a) A produces datum, waits until B consumes it
(b) A and B are autonomous activities that have different sp
(b1)
B can read the datum from A and consume it
(b2)
a pipe is inserted between A and B
Chinese University, CSE Dept.
Software Engineering / 4 - 32
Software Engineering / 4 - 33
d1
d2
dn
Figure 4.6 A partial DFD augmented with control flow arrows. The trigger
is a control flow arrow. It is dashed rather than continuous. The
function sum associated with the bubble is applied to all data
existing in the boxes as soon as a trigger occurs.
Chinese University, CSE Dept.
Software Engineering / 4 - 34
return
book
librarian
customer
library
update
Chinese University, CSE Dept.
Software Engineering / 4 - 35
Software Engineering / 4 - 36
Librarian
membercard+
book request
Catalogue
membership
OK
bookrequest
time
bookavailable
bookborrowed
Software Engineering / 4 - 37
Customer
3: book request
Librarian
5: book borrowed
Catalogue
4: book available
Software Engineering / 4 - 38
Software Engineering / 4 - 39
q1
q2
qk
qn
q1
q
2
qj
qn ..
..
..
i
..
..
in-coming arcs
qj
qk
iff (sj, i) = sk
out-going arcs
Software Engineering / 4 - 40
q1
a
Of
On
q0
Push switch
q2
Push switch
b
q3
High-pressure alarm
Figure 4.7
High-temperature alarm
On
Off
Figure 4.9
Chinese University, CSE Dept.
Restart
Software Engineering / 4 - 41
Normal
Pressure
Pressure
action
action
Suc cessful
recovery
Temperature signal
Unsuccessful
recovery
Normal
Of
Off
Successful
recovery
Temperature signal
Unsuccessful
rec overy
Temperature
ac tion
Pressure signal
Figure 4.10
Chinese University, CSE Dept.
Software Engineering / 4 - 42
: Q I Q O
Software Engineering / 4 - 43
FSMs as Recognizers
q1
q2
q3
q4
b
q0
qf
e
q5
q6
qf is a final state
Software Engineering / 4 - 44
FSMs as Recognizers
<letter>
<digit>
q
<letter>
<letter>
q1
q2
<digit>
<letter>
<digit>
Chinese University, CSE Dept.
advantages:
(1) simple
(2) widely used
disadvantages:
(1) its computational power is limited due to finite memory. e.g.,
hard to deal with real numbers whose possible values are infinite.
(2) number of states may be explosive
Software Engineering / 4 - 46
Software Engineering / 4 - 47
Software Engineering / 4 - 48
Producer
p1
p2
write
read
Consumer
c1
c2
consume
write
Buffer
0
read
Figure 4.13
write
read
Software Engineering / 4 - 49
producers state
consumers state
write
write
<1, p ,c >
1 1
consume
consume
produce
consume
produce
<0, p ,c >
2 1
<2, p1 ,c >
1
produce
<1, p ,c>
2 1
<2, p ,c >
2 1
read
<0, p ,c >
1 2
<1, p ,c >
1 2
<2, p ,c >
1 2
read
produce
consume
<0, p2 , c2 >
read
write
produce
consume
read
write
<1, p ,c2>
2
produce
consume
Figure 4. 14
<2, p ,c2>
2
Software Engineering / 4 - 50
Software Engineering / 4 - 51
stop
ConcurrentWork
write
P1
write
read
produce
read
read
write
P2
Producer
C1
Buffer
consume
C2
Consumer
Software Engineering / 4 - 52
C) Petri Nets:
Specifying Asynchronous Systems
[Petri 1962] C.A. Petri Ph.D Dissertation U of Bonn.
Basic elements
1) a finite set of places (circles)
Software Engineering / 4 - 53
C) Petri Nets
Figure. 4.16
Chinese University, CSE Dept.
Software Engineering / 4 - 54
C) Petri Nets
A quadruple (P,T,F,W)
P: places T: transitions (P, T are finite)
F: flow relation (F {PT} {TP} )
W: weight function (W: F N {0} )
Properties:
(1) P T =
(2) P T
(3)F (P T) (T P)
(4) W: F N-{0}
Default value of W is 1
State defined by marking: M: P N
Chinese University, CSE Dept.
Software Engineering / 4 - 55
C) Petri Nets
Operation of a Petri Net (PN)
1) state: a PN is given a state by marking its places.
2) marking: assign a token to each place of a PN.
3) token: a non-negative integer (usually 0 or 1) inserted to
the places of a PN.
4) input place (__________): if an arrow goes from a place
to a transition (________ or ________), the place is one
of the transitions input places.
enough tokens in a place means ___________________
Software Engineering / 4 - 56
C) Petri Nets
7) fire: the number of input weight tokens are removed from
each input place and the number of output weight tokens
are inserted in each output place of the transition. An
enabled transition may fire.
8) non-determinism: given an initial marking, different
evolutions of the PN are possible.
9) firing sequence: a sequence of transition firings, denoted as
a string of transition labels <t1,t2,,tn>, such that t1 is fired in
the initial marking, then t2 is fired, and so on.
Example: Figure 4.16(a)
C) Petri Nets
Figure. 4.16(a)-(d)
Chinese University, CSE Dept.
Software Engineering / 4 - 58
C) Petri Nets
12)starvation: a process that never receives
access to a needed resource.
Starvation may happen due to ______________
Put two tokens in p3
{
no _______________
no ________________
C) Petri Nets
Software Engineering / 4 - 60
C) Petri Nets
Figure. 4.17
A Petri net that can enter a deadlock state
Software Engineering / 4 - 61
C) Petri Nets
13)deadlock: a PN with a given marking is said to
be in deadlock iff no transition is enabled in
that marking.
14)live: a PN without deadlock.
E.g. Figure 4.18
Q: deadlock starvation ?
_________________
Q: starvation deadlock ?
Software Engineering / 4 - 62
Figure. 4.18
A modification of the Petri net of Figure 4.17 that is live.
Chinese University, CSE Dept.
Figure. 4.19
A Petri net with partial starvation.
Software Engineering / 4 - 63
consume
consume
P1
C1
C2
P
2
read
C
C1
produce
read
read
read
integration
read
write
0
P1
write
write
produce
P2
write
Figure. 4.20
Chinese University, CSE Dept.
Software Engineering / 4 - 64
Figure. 4.21
An integrated Petri net describing
a producer-consumer system.
Software Engineering / 4 - 65
C) Petri Nets
advantages over FSM:
1) graphical complexity - state space of the
components is only additive, not multiplicative
Major reduction of model complexity
Software Engineering / 4 - 66
C) Petri Nets
Q: modify it so that buffer
is 3.
Figure. 4.21
An integrated Petri net describing
a producer-consumer system.
Software Engineering / 4 - 67
C) Petri Nets
PN limitations
1) PN tokens are anonymous (no values), which
couldnt specify special firing conditions
Channel 1 Channel 2
(for correct (for incorrect
message)
message)
Software Engineering / 4 - 68
C) Petri Nets
P1
P2
P3
t1
P4
t3
t2
P
t4
P6
t5
t6
Software Engineering / 4 - 69
C) Petri Nets
PN extensions
1) assign values to tokens: Colored-Petri Net
P1
t1
P2
7
4
t2
P4
Figure 4.22 A Petri net whose tokens carry values. The predicate P2 > P1 and the Function
P4 := P2 + P1 are associated with T1; the predicate P3 = P2 and the functions
P4 := P3 P2 and P5 := P2 + P3 are associated with t2
Software Engineering / 4 - 70
C) Petri Nets
3) timed Petri nets in which a pair <tmin,tmax> is
associated with each transition.
p1
p2
t1
p3
t2
tmin = 1
tmin = 2
tmax = 4
tmax = 3
priority = 1 (low) priority = 3 (high)
=> t1 cannot fire between 2 t 3
An earlier example
A more precise spec by choosing Figure 4.23 or Figure 4.24
Software Engineering / 4 - 71
Original message
= c1
{ tmin
tmax = k1
Message triplication
Message copies
= c2
{ tmin
tmax = k2
PC1
tmin = 0
tmax = 0
for all three transitions
tvoting1
tvoting2
tvoting3
Forwarded message
Figure 4.23
Software Engineering / 4 - 72
Original message
tmin = c1
tmax = k1
Message triplication
Message copies
tmin = c2
tmax = k2
tmin = 0
tmax = 0
PC3
tvoting
Figure 4.24
Forwarded message
Software Engineering / 4 - 73
Descriptive Specifications
Describe the desired _________ of a system rather
than the desired ___________
Software Engineering / 4 - 74
Software Engineering / 4 - 75
SEX
ENROLLED_IN
SUBJECT
CLASS
COURSE_ID
M AX_ENROLLM ENT
one to many
many to one
many to many
Chinese University, CSE Dept.
Software Engineering / 4 - 77
Data
HeadOf
Director
Department
Participate
Assigned
Project
Employee
Software Engineering / 4 - 78
Software Engineering / 4 - 79
Software Engineering / 4 - 80
7: true or false?
True if x is _________; false if x is ___________
Combine with ER diagrams: See the Figure in next page.
Chinese University, CSE Dept.
Software Engineering / 4 - 81
NAM E
AGE
STUDENT
SEX
ENROLLED_IN
SUBJECT
CLASS
COURSE_ID
b in CLASS
5 cardinality { a | <a,b> in
ENROLLED_IN }
b.MAX_ENROLLMENT
a: student b: class
M AX_ENROLLM ENT
Chinese University, CSE Dept.
Software Engineering / 4 - 82
Pre - __________________ of P
Post - _________________ of P
Software Engineering / 4 - 84
Software Engineering / 4 - 85
input_text(m,n)
( im = # and in = # and
( exists k (for all j (1 j k) implies
( exists hj, mj (input_word(mj,mj + hj) and n: last word ends at
position m + h
m : first word start
m1 = m + 1 and mk + hk + 1 = n and
from position m + 1
(1 j < k) implies (mj+1 = mj + hj + 2 and
imj+hj+1 = ) ) ) ) ) ) j+1 word starts from the ending
k
th
Software Engineering / 4 - 86
#we_shall_overcome#
k = ____
m1 = ____
m2 = ____
m3 = ____
h1 = ____
h2 = ____
h3 = ____
m1+h1 = ____ m2+h2 = ____ m3+h3 = ____
specifying a complete program quickly become very complicated and tedious
Software Engineering / 4 - 87
Software Engineering / 4 - 88
Software Engineering / 4 - 89
Software Engineering / 4 - 90
Software Engineering / 4 - 91
Predefined
Formats
Document
production
User
Formatting
options
Customer data
(name, type of
document)
Customers
Print
Document
Chinese University, CSE Dept.
Software Engineering / 4 - 92
Print document
(b)
Software Engineering / 4 - 93
Software Engineering / 4 - 94
Software Engineering / 4 - 95
Software Engineering / 4 - 96
Software Engineering / 4 - 97