This class models an account. A number of cards held by individual cardholders
are associated with an account. An account has a balance and records transactions.
The invariant ensures that transactions performed on the same day donot
exceed the daily limit, which is a constant value defined below. Note that
we have chosen tonot allow a negative balance.
\begin{vdm_al} values
dailyLimit : nat = 2000;
types public AccountId = nat; public Transaction :: date : Clock`Date
cardId : Card`CardId
amount : nat;
\end{vdm_al}
In this specification we have chosen to model transaction as a type.
Alternatively it could have been modeled as a class, but it has no obvious
functionality except trivial read/write operations. Moreover, transaction
objects/valuesdonot need tobe shared among many objects. Our choice also
illustrates the powerof the VDM++ type system.
\begin{vdm_al} operations public Account : mapCard`CardId to Cardholder * nat ==> Account
Account(cs,b) ==
(cards := cs;
balance := b);
pure public GetBalance : () ==> nat
GetBalance() == return balance;
\end{vdm_al}
The Withdrawal operation checks that an account and the daily limit are not overdrawn.
\begin{vdm_al} public Withdrawal : Card`CardId * nat * Clock`Date ==> bool
Withdrawal(cardId,amount,date) == let transaction = mk_Transaction(date,cardId,amount) in if balance - amount >= 0 and
DateTotal(date,transactions^[transaction]) <= dailyLimit then
(balance := balance - amount;
transactions := transactions ^ [transaction]; returntrue) else returnfalse pre cardId insetdom cards;
pure public MakeStatement : Card`CardId * Clock`Date ==> Letter
MakeStatement(cardId,date) == let nm = cards(cardId).GetName(),
addr = cards(cardId).GetAddress() in returnnew Letter(nm,addr,date,transactions,balance) pre cardId insetdom cards;
\end{vdm_al}
The GetCardIds operation is used to obtain all cards associated with the account.
\begin{vdm_al}
pure public GetCardIds: () ==> setofCard`CardId
GetCardIds() == returndom cards;
\end{vdm_al}
The following operationsandfunctions provide auxiliary functionality of various sorts.
The transactions invariant first computes all dates in the sequence of transactions andthen compares the sum of the drawn amounts for each day with the daily limit.
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.