Title: VDMSL Case Study
1VDM-SL Case Study
Learning Outcomes
At the end of this lecture you should be able to
- Analyse and informally specify a complete system
using UML class diagrams - Develop a formal VDM specification from an
informal UML specification. - Rigorously interrogate a formal specification
2The Requirements Definition
The software is expected to be able to do the
following
- create a new account
- remove an existing account
- record a deposit transaction
- record a withdrawal transaction
- update the personal details (name, address and so
on) of a customer's account - change the overdraft limit associated with an
account - produce a statement of transactions associated
with an account - display the balance of an account
- display the personal details of an account.
3The UML specification
AccountSys accounts Account addAccount
(AccNum, Details, Real) removeAccount
(AccNum) deposit(AccNum, Date, Real) withdraw(AccN
um, Date, Real) changeDetails(AccNum,
Details) changeLimit(AccNum, Real) getAllTransacti
ons(AccNum) Transaction getBalance(AccNum)
Real getAccount(AccNum) Account getDetails(AccNu
m) Details getLimit(AccNum)
Real getAllAccounts() Account
contains(AccNum) Boolean isEmpty()
Boolean getTotal() Integer
4Additional types The Account type
Account number AccNum details
Details balance Real limit Real transactions
Transaction
5Additional types The Transaction type
Transaction date Date type TransactionType amo
unt Real
6Additional types The TransactionType type
ltltenumerationgtgt TransactionType withdrawal deposi
t
7Formally specifying the types in VDM-SL
types AccNum TOKEN Date TOKEN Details
TOKEN TransactonType lt withdrawal gtlt deposit
gt
8Formally specifying the types in VDM-SL
Transaction date Date amount
? transactionType TransactionType inv
mk-Transaction(-,a,-) ? a gt 0
9Formally specifying the types in VDM-SL
Account number AccNum details
Details balance ? limit
? transactions Transaction inv
mk-Account(-,-,b,l,t) ?
l 0
limit is non-negative
? b -l
balance within limit
? balanceOf(t) b
balance matches transactions
10Formally specifying the state in VDM-SL
state AccountSys of accounts
Account
AccNum
inv mk-AccountSys(a) ? account numbers in
domain also in range
? num ? dom a ? num a(num).number
init mk-AccountSys(a) ? a ? end
11Auxiliary functions balanceOf
balanceOf( transIn Transactions ) total
? pre true post let dep transIn(i).amount
i ? inds transIn ? transIn(i).transact
ionType ltdepositgt in let withd
transIn(i).amount i ? inds transIn
? transIn(i).transactionType ltwithdrawalgt
in total sum(dep) - sum(withd)
?
?
true
?
?
?
?
?
?
?
12Auxiliary functions sum
sum ? ? ? sum(seqIn) ? if seqIn
then 0 else hd seqIn sum(tl seqIn)
13Operation specifications addAccount
addAccount( ) ext pre post
numberIn AccNum, detailsIn Details, limitIn
?
wr
accounts
numberIn ? dom accounts
? limitIn ? 0
numberIn ? mk-Account(numberIn, detailsIn, 0,
limitIn,
14Operation specifications removeAccount
removeAccount( ) ext
pre post
numberIn AccNum
wr
accounts
numberIn ? dom accounts
accounts numberIn
15Operation specifications deposit
deposit( ) ext pre post
numberIn AccNum, dateIn Date, amountIn ?
wr
accounts
? amountIn gt 0
numberIn ? dom accounts
let bal ( (numberIn)).balance
in let trans (
(numberIn)).transactions
in let newTrans mk-Transaction(dateIn,
amountIn,lt depositgt)
in accounts numberIn ?
?( (numberIn), balance ?
bal amountIn, transactions ? trans
newTrans)
16Operation specifications withdraw
withdraw( ) ext pre post
numberIn AccNum, dateIn Date, amountIn ?
wr
accounts
? amountIn gt 0
numberIn ? dom accounts
? (accounts(numberIn)).balance - amountIn -
(accounts(numberIn)).limit
let bal ( (numberIn)).balance
in let trans (
(numberIn)).transactions
in let newTrans mk-Transaction(dateIn,
amountIn,lt withdrawalgt)
in accounts numberIn ?
?( (numberIn), balance ?
bal - amountIn, transactions ? trans
newTrans)
17Operation specifications changeDetails
changeDetails( ) ext pre post
numberIn AccNum, detailsIn Details
wr
accounts
numberIn ? dom accounts
accounts numberIn ?
?( (numberIn), details ? detailsIn)
18Operation specifications changeLimit
changeLimit( ) ext pre post
numberIn AccNum, limitIn ?
wr
accounts
numberIn ? dom accounts
? limitIn ? 0
? accounts(numberIn).balance ? - limitIn
accounts numberIn ?
?( (numberIn), limit ? limitIn)
19Operation specifications getDetails
getDetails( ) ext pre post
numberIn AccNum
detailsOut Details
rd
accounts
numberIn ? dom accounts
detailsOut (accounts(numberIn)).details
20Operation specifications getBalance
getBalance( ) ext pre post
numberIn AccNum
balanceOut ?
rd
accounts
numberIn ? dom accounts
balanceOut (accounts(numberIn)).balance
21Operation specifications getLimit
getLimit( ) ext pre post
numberIn AccNum
limitOut ?
accounts
rd
numberIn ? dom accounts
limitOut (accounts(numberIn)).limit
22Operation specifications getAllTransactions
getAllTransactions( ) ext pre post
numberIn AccNum
transactionsOut Transaction
rd
accounts
numberIn ? dom accounts
transactionsOut (accounts(numberIn)).transactio
ns
23Operation specifications contains
contains( ) ext pre post
numberIn AccNum
query ?
rd
accounts
TRUE
query ? numberIn ? dom accounts
24Operation specifications isEmpty
isEmpty( ) ext pre post
query ?
rd
accounts
TRUE
query ? accounts ?
25Operation specifications getTotal
getTotal( ) ext pre post
totalOut ?
rd
accounts
TRUE
totalOut card dom accounts
26Rigorously checking specifications
One of the advantages of formal specifications is
that they can tested before an implementation
is developed.
Test
Test
27Example
If I create a new account with an overdraft
limit of 200, I will not be allowed to withdraw
300 until after more money has been deposited.
addAccount (AccNum, Details, Real) removeAccount
(AccNum) deposit(AccNum, Date, Real) withdraw(AccN
um, Date, Real) changeDetails(AccNum,
Details) changeLimit(AccNum, Real) getAllTransacti
ons(AccNum) Transaction getBalance(AccNum)
Real getAccount(AccNum) Account getDetails(AccNu
m) Details getLimit(AccNum)
Real getAllAccounts() Account
contains(AccNum) Boolean isEmpty()
Boolean getTotal() Integer
28Example
If I create a new account with an overdraft
limit of 200, I will not be allowed to withdraw
300 until after more money has been deposited.
addAccount ( AccNum, Details , Real )
001
200
withdraw( AccNum , Date , Real )
001
300
29addAccount( ) ext pre post
numberIn AccNum, detailsIn Details, limitIn
?
wr
accounts
numberIn ? dom accounts
? limitIn ? 0
001
200
numberIn ? mk-Account( numberIn , detailsIn ,
0, limitIn ,
001
001
200
withdraw( ) ext pre
numberIn AccNum, dateIn Date, amountIn ?
wr
accounts
300
? amountIn gt 0
numberIn ? dom accounts
001
? (accounts(numberIn)).balance - amountIn -
(accounts(numberIn)).limit
001
001
300