Lecture4 Formal
Lecture4 Formal
Lecture4 Formal
Lecture 4
Composite Objects
Mohamed Mead
Aims
Learning Outcomes At the end of this lecture you should
be able to:
Identify when it is appropriate to use a composite object type
The Time type can be used to specify types of state variables. For
example, importantTimes is a set of Time objects:
importantTimes: Time-set
Composite objects – general format
The general format of a composite object comprises the object name
followed by the symbol :: followed by each fieldname and its type, the
field name and type separated by a colon (:)
types
TypeName :: fieldname1 : Type1
fieldname2 : Type2
…
Composite objects - operations
VDM-SL supports three operations on composite object
types:
make – to make composite objects
.
Composite objects – make function
For example, we can make a Time object, named someTime, for the time
16 hours, 20 minutes and 44 seconds:
someTime = mk-Time ( 16 , 20 , 44 )
Composite object invariants
types
Time :: hour: N
minute: N
second: N
inv mk-Time (h, m, s) ∆ h < 24 ∧ m < 60 ∧ s < 60
7
Composite objects – selectors
Individual fields are selected by the dot operator '.’ followed by the name of a field
someTime = mk-Time ( 16 , 20 , 44 )
then, someTime.minute is 20
and, someTime.hour is 16
8
Composite objects – mu function
10
The Disk Scanner
A disk is divided into a number of tracks and each track into a number of
sectors.
11
disk, tracks, sectors and blocks
disk
track
sector
12
The UML specification
DiskScanner Block
damagedBlocks: Block [*]
track: Integer
sector: Integer
addBlock(Integer, Integer)
removeBlock (Integer, Integer)
isDamaged(Integer, Integer): Boolean A block comprises a track
getBadSectors(Integer): Integer [*] and a sector number
13
Specifying the data model in VDM-SL
Block
types track: Integer
Block :: track: N sector: Integer
sector: N
14
The addBlock operation
15
The removeBlock operation
16
The isDamaged operation
pre TRUE
post query ⇔
mk-Block (trackIn, sectorIn) ∈ damagedBlocks
17
The getBadSectors operation
pre TRUE
post list =
{ b.sector | b ∈ damagedBlocks ● b.track = trackIn }
18
The complete VDM-SL specification
types
Block :: track: N
sector: N
state DiskScanner of
damagedBlocks: Block-set
init mk-DiskScanner (dB) ∆ dB = { }
end
operations
addBlock (trackIn: N, sectorIn: N )
ext wr damagedBlocks: Block-set
pre mk-Block (trackIn, sectorIn) ∉ damagedBlocks
post damagedBlocks = damagedBlocks ∪ { mk-Block (trackIn, sectorIn) }
removeBlock (trackIn: N, sectorIn: N )
ext wr damagedBlocks: Block-set
pre mk-Block (trackIn, sectorIn) ∈ damagedBlocks
post damagedBlocks = damagedBlocks \ { mk-Block (trackIn, sectorIn) }
isDamaged (trackIn: N, sectorIn: N ) query : B
ext rd damagedBlocks: Block-set
pre TRUE
post query ⇔ mk-Block (trackIn, sectorIn) ∈ damagedBlocks
getBadSectors (trackIn : N) list : N-set
ext rd damagedBlocks: Block-set
pre TRUE
post list = { b.sector | b ∈ damagedBlocks ● b.track = trackIn }
19
Case study
20
A process management system
In multi-tasking operating systems processes are identified by a unique process
identification number (pid).
When a process is created it joins the list of waiting processes, in the READY state.
(admit)
Processes are allocated to the CPU in a simple first-in-first-out policy:
• When the CPU becomes available, the first READY process in the queue is
allocated to the CPU and removed from the waiting list. (dispatch)
Each running process is allotted a fixed amount of CPU time (a quantum). If a
process uses up its allotted time before it terminates, it is placed back at the end
of the waiting queue with a READY status (timeout); if it has finished, it is removed
from the system (not put back in the queue). (terminate)
If the process did not time out but could not proceed for some reason (e.g. waiting
for an input/output operation), it is put back at the end of the waiting queue with
a BLOCKED status. (block)
When a blocked process is ready to be processed again, it is woken up from its
BLOCKED status and is once again in a READY state. (wakeup)
21
process management – diagram
ProcessManagement Process
running: String id: String
waiting: Process[*] status: Status
admit(String)
dispatch()
timeOut() <<enumeration>>
block() Status
wakeUp(String) READY
terminate() BLOCKED
23
THANK YOU
24