Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 64

Specification

Ch. 5

Outline
Discussion of the term "specification"
Types of specifications
operational
Data Flow Diagrams
(Some) UML diagrams
Finite State Machines

descriptive
Entity Relationship Diagrams

Languages for modular specifications


Statecharts

Ch. 5

Specification
Discussion of the term "specification"
What does software specification mean?
Do we need that?

Ch. 5

Ch. 5

Specification
A broad term that means definition
Used at different stages of software
development for different purposes
Generally, a statement of agreement
(contract) between
producer and consumer of a service
implementer and user

All desirable qualities must be


specified
Ch. 5

Uses of specification
Statement of user requirements
major failures occur because of
misunderstandings between the
producer and the user
"The hardest single part of building a
software system is deciding precisely
what to build" (F. Brooks)

Ch. 5

Uses of specification (cont.)


Statement of the interface between
the machine and the controlled
environment
serious undesirable effects can result
due to misunderstandings between
software engineers and domain experts
about the phenomena affecting the
control function to be implemented by
software
Ch. 5

Uses of specification (cont.)


A reference point during
maintenance
corrective maintenance only changes
implementation
adaptive and perfective maintenance
occur because of requirements
changes
requirements specification must change
accordingly
Ch. 5

Specification qualities
Precise, clear, unambiguous
Consistent
Complete
Incremental

Ch. 5

Clear, unambiguous,
understandable
Example: specification fragment for a
word-processor. A select command.
Selectingistheprocessofdesignating
areasofthedocumentthatyouwanttowork
on.Mosteditingandformattingactions
requiretwosteps:firstyouselectwhatyou
wanttoworkon,suchastextorgraphics;
thenyouinitiatetheappropriateaction.

Ch. 5

10

Clear, unambiguous,
understandable
Example: specification fragment for a
word-processor. A select command.
What does area mean? Can an area be a collection of
sequence of scattered characters?

Ch. 5

11

Precise, unambiguous, clear


Another example (from a real
safety-critical system)
Themessagemustbetriplicated.Thethree
copiesmustbeforwardedthroughthree
differentphysicalchannels.Thereceiver
acceptsthemessageonthebasisofa
twooutofthreevotingpolicy.

Ch. 5

12

Precise, unambiguous, clear


Another example (from a real
safety-critical system)
Can a message be accepted as soon as we receive 2 out
identical copies of message or do we need to wait for
receipt of the 3rd?

Ch. 5

13

Consistent
Example: specification fragment for a
word-processor
Thewholetextshouldbekeptinlines
ofequal length.Thelengthisspecified
bytheuser.Unlesstheusergivesan
explicithyphenationcommand,
acarriagereturnshouldoccuronly
attheendofaword.

Ch. 5

14

Consistent
Example: specification fragment for a
word-processor

What if the length of a word exceeds the length of the l

Ch. 5

15

Complete
Internal completeness
the specification must define any new
concept or terminology that it uses
glossary helpful for this purpose

the specification must document all


the needed requirements
difficulty: when should one stop?

Ch. 5

16

Incremental
Referring to the specification
process
start from a sketchy document and
progressively add details

Referring to the specification


document
document is structured and can be
understood in increments
Ch. 5

17

Classification of
specification styles
Informal, semi-formal, formal
Operational
Behavior specification in terms of
some abstract machine

Descriptive
Behavior described in terms of
properties
Ch. 5

18

Example 1
Specification of a geometric figure E:
E can be drawn as follows:
1. Select two points P1 and P2 on a plane
2. Get a string of a certain length and fix its ends
to P1 and P2
3. Position a pencil as shown in next figure
4. Move the pen clockwise, keeping the string
tightly stretched, until you reach the point where
you started drawing
this is an operational specification
Ch. 5

19

P1

P
2

Implementing the specification of a


circle
Ch. 5

20

A descriptive specification
Geometric figure E is described by
the following equation
ax2 + by2 + c = 0
where a, b, and c are suitable
constants

Ch. 5

21

Another example
OP

Let a be an array of n elements. The result of its sorting


is an array b of n elements such that the first element of
b is the minimum of a (if several elements of a have the
same value, any one of them is acceptable); the second
element of b is the minimum of the array of n-1
elements obtained from a by removing its minimum
element; and so on until all n elements of a have been
removed.

The result of sorting array a is an array b which is a


DES permutation of a and is sorted.
Ch. 5

22

How to verify a
specification?
Observe dynamic behavior of
specified system (simulation,
prototyping, testing specs)
Analyze properties of the specified
system
Analogy with traditional engineering
physical model of a bridge
mathematical model of a bridge
Ch. 5

23

Data Flow Diagrams (DFDs)


A semi-formal operational specification
System viewed as collection of data
manipulated by functions
Data can be persistent
they are stored in data repositories

Data can flow


they are represented by data flows

DFDs have a graphical notation

Ch. 5

24

Graphical notation
bubbles represent functions
arcs represent data flows
open boxes represent persistent
store
closed boxes represent I/O
interaction
The function symbol

The input device symbol

The data flow symbol


The output device symbol

The data store symbol


Ch. 5

25

Example
specifies evaluation of
(a + b) * (c + a * d)

Ch. 5

26

A construction method (1)


1. Start from the context diagram
Input
Input

Output

1
2

Input n

information

...

system

Ch. 5

...

Output
Output

1
2
m

27

A construction method (2)


2. Proceed by refinements until you
reach
elementary functions
(preserve balancing)
A

H
I

A3
J

A4

A1
K
A2

K2

S
N

A6

P
A5

B2
K3

K1
T

B1

Ag

A7

B3

B4
K4

Ch. 5

28

A library system
User request consisting of title, name
of author
Access to the shelves that contain the
book.
List of authors
List of titles
Users name

Ch. 5

29

A library example
Book

Book request
by the user

Shelves

Title and author


of requested book; name
of the user

Author

Book

List of Authors

Get a book
Title

Book
reception

Book title;
user name

List of titles

List of books borrowed

Title
Search by
topics

List of topics
Topic

Topic

Topic request
by the user

List of titles
referring to the topic

Ch. 5

Display of
the list of titles

30

Refinement of
Get a book
Book

Shelves
Author

Get
the book

Book

List of Authors
<shelf#, book#>

Find
book
position

Title

Book
reception

List of books borrowed

List of titles
Title and author
of requested book;
name of the user

Book title;
user name

Book request
by the user
Ch. 5

31

An evaluation of DFDs
Semantics of the symbols is
determined only by the identifiers
provided (find book position, +)
Access to the shelves that contain the
book.
List of authors
List of titles
Users name

Ch. 5

32

Patient monitoring systems


The purpose is to monitor the patients vital factors--blood,
pressure, temperature, --reading them at specified frequencies
from analog devices and storing readings in a DB. If readings fall
outside the range specified for patient or device fails an alarm
must be sent to a nurse. The system also provides reports.

Ch. 5

33

An evaluation of DFDs (1)


Semantics of the symbols is determined
only by the identifiers provided (find
book position, +)
Attractive graphical notation suitable for
capturing, in a fairly immediate and
intuitive way, the flow of data and the
operations involved in an information
system.
Its intuitive meaning not suitable for
machine interpretation.
Ch. 5

34

An evaluation of DFDs (2)


Easy to read, but
Informal semantics
How to define leaf functions?
Inherent ambiguities

A
E
B

Outputs from A, B, C are


all needed?
Outputs for E and F are
produced at the same tim

D
F

Ch. 5

35

An evaluation of DFDs (3)


Control information is absent
A

Possible interpretations:
(a) A produces datum, waits until B consumes it
(b) B can read the datum many times without
consuming it
(c) a pipe is inserted between A and B. A denotes
computing time spent by employees in their work
and B denotes computing a payroll.

Ch. 5

36

Formalization/extensions
There have been attempts to formalize
DFDs
There have been attempts to extend
DFDs (e.g.,
for real-time systems)
d1
Trigger
d2

.
.
.

dn

Ch. 5

37

UML use-case diagrams


Define functions on basis of actors
and actions
borrow
book

return
book

librarian

customer
library
update

Ch. 5

38

UML sequence diagrams


Describe how objects interact by
exchanging messages
Provide a dynamic view
Customer

Librarian

Catalogue

membercard+
book request

membership
OK
bookrequest

time

bookavailable
bookborrowed

Ch. 5

39

UML collaboration diagrams


Give object interactions and their order
Equivalent to sequence diagrams
2: membership OK
1: member card +
book request

Customer

3: book request

Librarian
5: book borrowed

Catalogue
4: book available

Ch. 5

40

Finite state machines


(FSMs)
Can specify control flow aspects
Defined as
a finite set of states, Q;
a finite set of inputs, I;
a transition function d : Q x I Q q
(d can be a partial function) a

a
b

q0
c

q2
b

q3

Ch. 5

41

Example: a lamp
Push switch

Of

On
Push switch

Ch. 5

42

Another example:
a plant control system
High-pressure alarm

High-temperature alarm

On

Off

Restart
Ch. 5

43

A refinement
Pressure signal

Normal

Pressure
Pressure
action
ac tion
Suc cessful
recovery

Temperature signal

Unsucc essful
recovery

Normal

Of

Off

Succ essful
recovery

Temperature signal

Unsuccessful
recovery

Temperature
ac tion

Ch. 5

Pressure signal

44

Classes of FSMs
Deterministic/nondeterministic
FSMs as recognizers
introduce final states

FSMs as transducers
introduce set of outputs

...
Ch. 5

45

FSMs as recognizers
q1

q2

q3

q4

b
q0

qf
e
q5

q6

qf is a final state
Ch. 5

46

FSMs as recognizers
<letter>
<digit>
q

<letter>

q1

<letter>

Legend:

<letter>

<digit>

q2

<digit>

is an abbreviation for a set of arrows


labeled a, b,..., z, A,..., Z,
respectively
is an abbreviation for a set of arrows
labeled 0, 1,..., 9, respectively
Ch. 5

47

Limitations
Finite memory
State explosion
Given a number of FSMs with k1, k2,
kn states, their composition is a FSM
with k1 * k2 * * kn. This growth is
exponential with the number of FSMs,
not linear (we would like it to be k1 +
k2 + + kn )
Ch. 5

48

State explosion: an example


produce

Producer
p1

p2

deposit
get

Consumer
c1

c2

consume
deposit

Storage
0

deposit
1

get

Ch. 5

get

49

The resulting FSM


write

write

<1, p ,c >
1 1

<0, p1 ,c1 >


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
Ch. 5

produce
consume
<2, p ,c2>
2
50

Declarative specifications
ER diagrams: semiformal
specs
Logic specifications
Algebraic specifications
Ch. 5

51

ER diagrams
Often used as a complement to
DFD to describe conceptual data
models
Based on entities, relationships,
attributes
They are the ancestors of class
diagrams in UML
Ch. 5

52

Example
NAM E
AGE
STUDENT

SEX

ENROLLED_IN

SUBJECT
CLASS

COURSE_ID
M AX_ENROLLM ENT

Ch. 5

53

Relations
Relations can be partial
They can be annotated to define
one to one

one to many

many to one

many to many A

Ch. 5

54

Non binary relations


Duration

Data

Director

HeadOf

Department

Participate

Assigned

Project
Employee

Ch. 5

55

Modularizing finite state


machines

Ch. 5

56

Modularizing finite state


machines
Statecharts do that
They have been incorporated in
UML
They provide the notions of
superstate
state decomposition

Ch. 5

57

Sequential decomposition
--chemical plant control example-Normal

AnomalyDetection

RecoverySuccess
Recovery
Press

Recovery
Identification
Temp

Done
Pressure
Action

Done
Temperature
Action

Ch. 5

RecoveryFailure

58

Parallel decomposition
Idle
start

stop

ConcurrentWork

write

P1

write

read
produce

read
read

write

P2
Producer

C1

Buffer

Ch. 5

consume
C2
Consumer

59

Object state diagram using


Statecharts
Top
Empty

Push(item)

NotEmpty
y
Pop[stack contains 1 item]

Push(item)

Pop[stack contains more than 1 item]

Ch. 5

60

Object state diagram using


Statecharts

Ch. 5

61

Specifications for the


end-user
Specs should be used as common
reference for producer and user
They help removing ambiguity,
incompleteness,
Can they be understood by end-user?
They can be the starting point for a
prototype
They can support some form of animation
Ch. 5

62

Conclusions (1)
Specifications describe
what the users need from a system (requirements
specification)
the design of a software system (design and
architecture specification)
the features offered by a system (functional
specification)
the performance characteristics of a system
(performance specification)
the external behavior of a module (module interface
specification)
the internal structure of a module (internal structural
specification)

Ch. 5

63

Conclusions (2)
Descriptions are given via suitable
notations
There is no ideal notation

They must be modular


They support communication and
interaction between designers and
users
Ch. 5

64

You might also like