This class models a till. A till is connected to a central resource and holds a number of retained cards, which have not been returned to
a user of the till. It may hold a current cardand it has an attribute to say whether the current cardand its PIN code have been validated
successfully. In this version of the till we assume that the central
resource will always become available within a reasonable time limit.
The invariant says that if there is no cardin the till then the
validation status of the current card shall befalse.
\begin{vdm_al} operations public Till: CentralResource ==> Till
Till(res) ==
resource := res;
\end{vdm_al}
The Create operation is used once in a till object's lifetime in order to set up a connection to a central resource.
\begin{vdm_al} public InsertCard : Card ==> ()
InsertCard(c) ==
curCard := c prenot CardInside();
\end{vdm_al}
The InsertCard operation models the activity of inserting a card into
the till. This cannot be done if the till holds a card already, which is documented in the precondition.
\begin{vdm_al} public Validate : Card`PinCode ==> <PinOk> | <PinNotOk> | <Retained>
Validate(pin) == let cardId = curCard.GetCardId(),
codeOk = curCard.GetCode() = Encode(pin),
cardLegal = IsLegalCard() in
(cardOk := codeOk and cardLegal; ifnot cardLegal then
(retainedCards := retainedCards union {curCard};
curCard := nil; return <Retained>) elseif codeOk then
resource.ResetNumberOfTries(cardId) else
(resource.IncrNumberOfTries(cardId); if resource.NumberOfTriesExceeded(cardId) then
(retainedCards := retainedCards union {curCard};
cardOk := false;
curCard := nil; return <Retained>)); returnif cardOk then <PinOk> else <PinNotOk>) pre CardInside() andnot cardOk;
\end{vdm_al}
The operation Validate is used to validate a PIN code andto check
that a cardisnot illegal. The precondition ensures that the till
currently holds a card which has notyet been validated. If a card
turns out tobe illegal, the machine keeps the card.
\begin{vdm_al} public ReturnCard : () ==> ()
ReturnCard() ==
(cardOk := false;
curCard:= nil) pre CardInside();
\end{vdm_al}
The ReturnCard operation is useful toend user sessions, though it is not mentioned in the requirements. It allows the user to perform more
than one transaction in each session, e.g. to first view the balance andthen make a withdrawal.
The following three operations are listed in the requirements
document. They all require that the till holds a card which has been
validated successfully. The operations are mirrored in the central
resource. The GetBalance operation return the value nilif it isnot
possible to get the balance.
\begin{vdm_al} public GetBalance : () ==> [nat]
GetBalance() ==
resource.GetBalance(curCard.GetAccountId()) pre CardValidated();
\end{vdm_al}
The MakeWithdrawal and RequestStatement operations returns a boolean
indicating whether the requested transactions could be completed.
\begin{vdm_al} public MakeWithdrawal : nat ==> bool
MakeWithdrawal(amount) ==
resource.Withdrawal
(curCard.GetAccountId(),curCard.GetCardId(),amount) pre CardValidated();
public RequestStatement : () ==> bool
RequestStatement() ==
resource.PostStatement(curCard.GetAccountId(),curCard.GetCardId()) pre CardValidated();
\end{vdm_al}
The IsLegalCard operation below is only used internally to validate a card.
\begin{vdm_al}
pure public IsLegalCard : () ==> bool
IsLegalCard() == return
resource.IsLegalCard(curCard.GetAccountId(),curCard.GetCardId()) pre CardInside();
pure public CardValidated: () ==> bool
CardValidated() == return curCard <> niland cardOk;
pure public CardInside: () ==> bool
CardInside() == return curCard <> nil;
functions
\end{vdm_al}
The requirements say that the till should encode the PIN code before
comparing it to the code on the card. We have documented this
requirement in the function below, but notyet made a choice of
approach to this.
\begin{vdm_al}
Encode: Card`PinCode +> Card`Code
Encode(pin) ==
pin; -- NB! The actual encoding procedure has not yet been chosen
end Till
\end{vdm_al}
¤ 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.0.26Bemerkung:
(vorverarbeitet)
¤
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.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.