API for a Supermarket Controller: Design Document
Document Number: E04
Date of Issue: 21 March 2005
Author: John B. Wordsworth
J.B.Wordsworth@ex.ac.uk
Copyright: © J. B. Wordsworth 2004, 2005
This document attempts to record an object-oriented development in a style similar to that taught on COM2404 Design and Method. It is intended as teaching material for COM3403 Information Systems Design.
See the document history for a record of changes.
The implementation of the back end consists of a number of classes:
The specification of each class is given under several headings:
Back to the table of contents.
String description int price int stock
Line (String des, int pri, int sto)
The new Line object has a description attribute of des, a price attribute of pri, and a stock attribute of sto.
The methods of the Line class are as follows:
String getDescr ()
Returns the value of the description attribute.
Back to the list of methods of the Line class, or to the table of contents.
String getPrice ()
Returns the value of the price attribute.
Back to the list of methods of the Line class, or to the table of contents.
void setPrice (int pri)
Sets the value of the price attribute to pri.
Back to the list of methods of the Line class, or to the table of contents.
int getStock ( )
Returns the value of the stock attribute.
Back to the list of methods of the Line class, or to the table of contents.
void changeStock (int sto)
Adjusts the value of the stock attribute by adding sto.
Back to the list of methods of the Line class, or to the table of contents.
String line Item next
next is not null.
Item (String lnu)
The new Item object has a line attribute that is lnu. The next attribute is this Item object.
The methods of the Item class are as follows:
Back to the list of methods of the Item class, or to the table of contents.
String getLine ( )
Returns the value of the line attribute.
Back to the list of methods of the Item class, or to the table of contents.
void chainItem (Item ite)
ite is not null.
Sets the next attribute to ite.
Back to the list of methods of the Item class, or to the table of contents.
Item unChain ( )
Returns next and sets next to this Item object.
boolean isEnd ( )
Returns true if and only if next is this Item object.
Back to the list of methods of the Item class, or to the table of contents.
Item getNext ( )
Returns next.
Back to the list of methods of the Item class, or to the list of classes, or to the table of contents.
Item first Item last boolean empty
If empty is false, first is not null and last is not null.
If empty is false, last is reachable from first by following the next chain.
If empty is false, the next attribute of last is itself.
Bill ( )
In the new Bill object, first is null, last is null, and empty is true.
The methods of the Bill class are as follows:
Back to the list of methods of the Bill class, or to the table of contents.
void enQueue (Item ite)
Sets the next attribute of last to ite, and sets last to ite.
Back to the list of methods of the Bill class, or to the table of contents.
Item deQueue ( )
empty is false.
If first and last are the same, return first, and set empty to true. If first and last are not the same, return last, set last to the predecessor of last in the chain, and set the last attribute of this Item object to this Item object.
Back to the list of methods of the Bill class, or to the table of contents.
boolean isEmpty ( )
Returns empty.
Back to the list of methods of the Bill class, or to the table of contents.
void remItem ( String lnu )
None.
If empty is true, do nothing. If empty is false, and if lnu is not the number attribute of any Item object starting at first and following the next chain as far as last, do nothing. If empty is false, and if ii is the first Item object in the next chain whose number attribute is lnu, remove ii from the chain.
Back to the list of methods of the Bill class, or to the list of classes, or to the table of contents.
Hashtable checkouts Hashtable bills Hashtable lines
(C1) The keys of checkouts are String objects.
(C2) The values of checkouts are null String objects.
(C3) Each key of bills is a key of checkouts.
(C4) The values of bills are Bill objects.
(C5) The keys of lines are String objects.
(C6) The values of lines are Line objects.
(C7) For each Bill object in the values of bills, if its empty attribute is false, then the line attribute of first, and of any Item object reachable from first by following the next chain, is a key of lines.
Store ( )
The new Store object has three empty Hashtable objects.
The following methods are private, and provide utility functions to the other methods.
The following methods provide the functional interface:
boolean isCheck ( String cnu )
Returns true if and only if cnu is a key of checkouts.
Back to the list of methods of the Store class, or to the table of contents.
boolean isBusy ( String cnu )
Returns the true if and only if cnu is a key of bills.
Back to the list of methods of the Store class, or to the table of contents.
boolean isLine ( String lnu )
Returns true if and only if lnu is a key of lines.
Back to the list of methods of the Store class, or to the table of contents.
boolean anyCheck ( )
Returns true if and only if checkouts is not empty.
Back to the list of methods of the Store class, or to the table of contents.
void addCheck ( String cnu )
Adds cnu as a key of checkouts with a null String value.
Back to the list of methods of the Store class, or to the table of contents.
void remCheck ( String cnu )
Removes cnu from the keys of checkouts.
Back to the list of methods of the Store class, or to the table of contents.
void addBill ( String cnu, Bill bb )
Adds the pair cnu, bb to bills.
Back to the list of methods of the Store class, or to the table of contents.
Bill getBill ( String cnu )
Returns the Bill object associated with key cnu in bills.
Back to the list of methods of the Store class, or to the table of contents.
void remBill ( String cnu )
Removes cnu and the corresponding Bill object from bills.
Back to the list of methods of the Store class, or to the table of contents.
void addLn ( String lnu, Line n1 )
Adds lnu as a key of lines with value n1.
Back to the list of methods of the Store class, or to the table of contents.
int addCheckout ( String cnu )
| Situation | Change of state | Outputs |
|---|---|---|
| cnu is a key of checkouts. | None. | Return 1. |
| cnu is not a key of checkouts. | Add a null String to checkouts with key cnu. | Return 0. |
Back to the list of methods of the Store class, or to the sequence diagram for this method, or to the table of contents.
int removeCheckout ( String cnu )
| Situation | Change of state | Outputs |
|---|---|---|
| cnu is not a key of checkouts. | None. | Return 1. |
| cnu is a key of checkouts. cnu is a key of bills. |
None. |
Return 2. |
| cnu is a key of checkouts. cnu is not a key of bills. |
Remove cnu from the keys of checkouts. |
Return 0. |
Back to the list of methods of the Store class, or to the sequence diagram for this method, or to the table of contents.
int startBill ( String cnu )
| Situation | Change of state | Outputs |
|---|---|---|
| cnu is not a key of checkouts. | None. | Return 1. |
| cnu is a key of checkouts. cnu is a key of bills. |
None. | Return 2. |
| cnu is a key of checkouts. cnu is not a key of bills. |
Let bb be a Bill object with the value true for its empty attribute, and add it to bills with cnu as its key. | Return 0. |
Back to the list of methods of the Store class, or to the sequence diagram for this method, or to the table of contents.
int addLineToBill ( String cnu, String lnu, StringBuffer lde, StringBuffer lpr )
| Situation | Change of state | Outputs |
|---|---|---|
| cnu is a key of bills.
lnu is a key of lines. |
Let ii be an Item object whose line attribute is lnu
and whose next attribute is itself. Modify the last of the Bill object whose key in bills is cnu so that its next is ii. Change the value of the last attribute of the Bill object to ii. |
Return 0. lde and lpr are the description and price attributes of the Line object that is associated with lnu in lines. |
| cnu is not a key of checkouts. | None. | Return 1. |
| lnu is not a key of lines. | None. | Return 2. |
| cnu is a key of checkouts. lnu is a key of lines. cnu is not a key of bills. |
None. | Return 3. |
Back to the list of methods of the Store class, or to the sequence diagram for this method, or to the table of contents.
int removeLineFromBill ( String cnu, String lnu )
| Situation | Change of state | Outputs |
|---|---|---|
| cnu is a key of checkouts. cnu is not a key of bills. |
None. | Return 3. |
| lnu is not a key of lines. | None. | Return 2. |
| cnu is not a key of checkouts. | None. | Return 1. |
| cnu is a key of bills. lnu is a key of lines. |
Let bb be the Bill object in bills whose key is cnu. If bb.empty is true, return 0. If bb.empty is false, remove any one Item in the first chain of bb whose line attribute has the value lnu. | Return 0. |
Back to the list of methods of the Store class, or to the sequence diagram for this method, or to the table of contents.
int endBill ( String cnu )
| Situation | Change of state | Outputs |
|---|---|---|
| cnu is not a key of checkouts. | None. | Return 3. |
| cnu is a key of checkouts. cnu is not a key of bills. |
None. | Return 2. |
| cnu is a key of bills. The empty attribute of the Bill object that is associated with the key cnu in bills is false. |
None. | Return 1. |
| cnu is a key of bills. The empty attribute of the Bill object that is associated with the key cnu in bills is true. |
Remove cnu from the keys of bills. | Return 0. |
Back to the list of methods of the Store class, or to the sequence diagram for this method, or to the table of contents.
int getLineFromBill ( String cnu, StringBuffer lde, StringBuffer pri )
| Situation | Change of state | Outputs |
|---|---|---|
| cnu is not a key of checkouts. | None. | Return 1. |
| cnu is a key of checkouts. cnu is not a key of bills. |
None. | Return 2. |
| cnu is a key of bills. The empty attribute of the Bill object that is associated with the key cnu in bills is true. |
None. | Return 3. |
| cnu is a key of bills. The empty attribute of the Bill object that is associated with the key cnu in bills is false. |
Let ii be the Item object that is the first attribute
of the Bill object with key cnu in bills. If ii is also the last attribute of the Bill object, set the empty attribute of the Bill object to true. If ii is not the last attribute of the Bill object, set the first attribute to ii.next. Let ll be the Line object that is the value associated with key ii.line in lines. |
Return 0. lde is ll.description. lpr is ll.price. |
Back to the list of methods of the Store class, or to the sequence diagram for this method, or to the table of contents.
int addLine ( String lnu, String lde, int pri, int sto )
| Situation | Change of state | Outputs |
|---|---|---|
| lnu is a key of lines. | None. | Return 1. |
| lnu is not a key of lines. | Let ll be a Line object whose description attribute is lde, whose price attribute is pri, and whose stock attribute is sto. Associate key lnu with ll in lines. | Return 0. |
Back to the list of methods of the Store class, or to the sequence diagram for this method, or to the table of contents.
int removeLine ( String lnu )
| Situation | Change of state | Outputs |
|---|---|---|
| lnu is not a key of lines. | None. | Return 1. |
| lnu is a key of lines. checkouts has at least one key. |
None. | Return 2. |
| lnu is a key of lines. checkouts has no keys. |
Remove lnu from the keys of lines. | Return 0. |
Back to the list of methods of the Store class, or to the sequence diagram for this method, or to the table of contents.
int setLinePrice ( String lnu, int pri )
| Situation | Change of state | Outputs |
|---|---|---|
| lnu is not a key of lines. | None. | Return 1. |
| lnu is a key of lines. | Change the price attribute of the Line object associated with lnu in lines to pri. | Return 0. |
Back to the list of methods of the Store class, or to the sequence diagram for this method, or to the table of contents.
int changeLineStock ( String lnu, int sto )
| Situation | Change of state | Outputs |
|---|---|---|
| lnu is not a key of lines. | None. | Return 1. |
| lnu is a key of lines. | Change the stock attribute of the Line object associated with lnu in lines by adding sto. | Return 0. |
Back to the list of methods of the Store class, or to the sequence diagram for this method, or to the table of contents.
This chapter defines a relationship between the back end specification and the class definitions, and verifies that the functional interface methods of the Store class implement the functional interface of the back end specification.
(R1) CheckoutNumber is a non-empty set of character arrays, represented by String, but is not otherwise defined.
(R2) LineNumber is a non-empty set of character arrays, represented by String or StringBuffer, but is not otherwise defined.
(R3) Integer is a non-empty set of integers, represented by int or Integer, but is not otherwise defined.
(R4) Description is a non-empty set of character arrays, represented by String or by StringBuffer, but is not otherwise defined.
(R5) checkout_set is the set of keys of checkouts.
(R6) line_set is the set of keys of lines.
(R7) description_function is the function derived from lines by relating each key to the description attribute of the corresponding Line object.
(R8) price_function is the function derived from lines by relating each key to the price attribute of the corresponding Line object.
(R9) stock_function is the function derived from lines by relating each key to the stock attribute of the corresponding Line object.
(R10) bill_line_function is the function derived from bills by relating each key to the sequence derived as follows:
The following functions are in the functional interface:
The type of the concrete input (String) guarantees the abstract precondition (cnu is in CheckoutNumber) by (R1).
In the first concrete partition, cnu is a key of checkouts, so by (R5) cnu is in checkout_set, which is the first abtract partition. The concrete change of state (none) is allowed by the abstract change of state (none). The concrete Return 1 agrees with the abstract status = 1.
In the second concrete partition, cnu is not a key of checkouts, so by (R5) cnu is not in checkout_set, which is the second abstract partition. The concrete change of state adds cnu to the keys of checkouts, which is allowed by the abstract change of state, which adds cnu to checkout_set by (R5). The concrete Return 0 agrees with the abstract status = 0.
Back to the list of functions, or to the table of contents.
The type of the concrete input (String) guarantees the abstract precondition (cnu is in CheckoutNumber), by (R1).
In the first concrete partition, cnu is not a key of checkouts, so cnu is not in checkout_set by (R5), which is the first abstract partition. The concrete change of state (none), is allowed by the abstract change of state (none). The concrete Return 1 agrees with the abstract status = 1.
In the second concrete partition, cnu is a key of checkouts, so cnu is in checkout_set by (R5). Further cnu is a key of bills, so cnu is in the domain of bill_line_function by (R10). Thus the second abstract partition is the one to use. The concrete change of state (none), is allowed by the abstract change of state (none). The concrete Return 2 agrees with the abstract status = 2.
In the third and final concrete partition, cnu is a key of checkouts, so cnu is in checkout_set by (R5). Further cnu is not a key of bills, so cnu is not in the domain of bill_line_function by (R10). Thus the third abstract partition is the one to use. The concrete state change removes cnu from the keys of checkouts, which removes cnu from checkout_set by (R5), and this is the abstract change of state. The concrete Return 0 agrees with the abstract status = 0.
Back to the list of functions, or to the table of contents.
To be supplied.
Back to the list of functions, or to the table of contents.
To be supplied.
Back to the list of functions, or to the table of contents.
To be supplied.
Back to the list of functions, or to the table of contents.
To be supplied.
Back to the list of functions, or to the table of contents.
To be supplied.
Back to the list of functions, or to the table of contents.
To be supplied.
Back to the list of functions, or to the table of contents.
To be supplied.
Back to the list of functions, or to the table of contents.
To be supplied.
Back to the list of functions, or to the table of contents.
To be supplied.
Back to the list of functions, or to the table of contents.
Sequence diagrams are provided for the following functions of the back end functional interface:
The following diagram shows the operation of addCheckout when it returns 0.
Back to the list of sequence diagrams, or to the specification for this method, or to the table of contents.
The following diagram shows the operation of removeCheckout when it returns 0.
Back to the list of sequence diagrams, or to the specification for this method, or to the table of contents.
The following diagram shows the operation of startBill when it returns 0.
Back to the list of sequence diagrams, or to the specification for this method, or to the table of contents.
The following diagrams shows the operation of addLineToBill when it returns 0.
Back to the list of sequence diagrams, or to the specification for this method, or to the table of contents.
The following diagram shows the operation of removeLineFromBill when it returns 0.
Back to the list of sequence diagrams, or to the specification for this method, or to the table of contents.
The following diagram shows the operation of endBill when it returns 0.
Back to the list of sequence diagrams, or to the specification for this method, or to the table of contents.
The following two diagrams shows the operation of getLineFromBill when it returns 0.
Back to the list of sequence diagrams, or to the specification for this method, or to the table of contents.
The following diagram shows the operation of addLine when it returns 0.
Back to the list of sequence diagrams, or to the specification for this method, or to the table of contents.
The following diagram shows the operation of removeLine when it returns 0.
Back to the list of sequence diagrams, or to the specification for this method, or to the table of contents.
The following diagram shows the operation of setLinePrice when it returns 0.
Back to the list of sequence diagrams, or to the specification for this method, or to the table of contents.
The following diagram shows the operation of changeLineStock when it returns 0.
Back to the list of sequence diagrams, or to the specification for this method, or to the table of contents.
To be supplied.
Back to the table of contents.
First issued.
Reissued with the following amendments:
Back to the table of contents.