-
-
Save mbrowne/97bcb11fbc56993ac337 to your computer and use it in GitHub Desktop.
Sketch of Borrow Library Items use case in trygve
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
context BorrowLibraryItems | |
{ | |
//Using init() method for initialization rather than constructor. | |
//See https://github.com/jcoplien/trygve/issues/69 | |
// | |
public BorrowLibraryItems init(User borrower, ItemRecordRepository itemRecordRepository) { | |
Catalog = itemRecordRepository; | |
ItemsToBorrow = new List<ItemRecord>(); | |
Librarian = this; | |
Borrower = borrower; | |
BorrowLibraryItemsController ctrl = new BorrowLibraryItemsController(); | |
ctrl.init(); | |
Controller = ctrl; | |
} | |
//start the use case | |
public void start() { | |
Controller.renderInitialScreen(); | |
Librarian.askToBeginScanning(); | |
} | |
role Librarian { | |
public void askToBeginScanning() { | |
Controller.setInstructions("Please begin scanning the items you would like to check out."); | |
} | |
public void askForNextItem() { | |
Controller.setInstructions("If you have more item(s) to check out, scan the next item now. " | |
+ "If you are done, press the Continue button."); | |
} | |
public void askToConfirmScannedItems() { | |
ItemsToBorrow.display(); | |
Controller.setInstructions("Please verify that these are the items you intend to check out."); | |
} | |
//TODO | |
//public void provideReceipt() | |
} | |
stageprop Borrower { | |
public void borrowItems() { | |
for (int i = 0; i < ItemsToBorrow.size(); i++) { | |
new BorrowItem().init(ItemsToBorrow.get(i)).borrow(); | |
} | |
Librarian.provideReceipt(); | |
} | |
} | |
requires { | |
int id(); | |
} | |
stageprop Controller { | |
public void renderInitialScreen() const { | |
//These are the two views that appear on the first screen | |
renderInstructionsView(); | |
renderItemsToBorrowView(); //note: this list is empty at this point | |
} | |
//Called when the borrower scans an item with the barcode scanner | |
public void scanItem(int itemId) const { | |
ItemRecord item = Catalog.getItemRecordById(itemId); | |
ItemsToBorrow.add(item); | |
Librarian.askForNextItem(); | |
} | |
//TODO | |
//public void removeItem(ItemRecord item) | |
public void proceedToConfirmation() const { | |
Librarian.askToConfirmScannedItems(); | |
} | |
//Called after the borrower reviews his/her selections and confirms them | |
public void confirmItemsToBorrow() const { | |
Borrower.borrowItems(); | |
} | |
//TODO | |
//public void printReceipt() | |
public void renderInstructionsView() const { | |
instructionsView().render(); | |
} | |
public void renderItemsToBorrowView() const { | |
itemsToBorrowView().render(ItemsToBorrow); | |
} | |
public void setInstructions(String instructions) const { | |
instructionsView().setInstructions(instructions); | |
instructionsView().refresh(); | |
} | |
public void refreshItemsToBorrowView() const { | |
itemsToBorrowView().refresh(); | |
} | |
} | |
requires { | |
public InstructionsView instructionsView() const; | |
public ItemsToBorrowView itemsToBorrowView() const; | |
//... | |
} | |
role ItemsToBorrow { | |
public void display() { | |
Controller.refreshItemsToBorrowView(); | |
} | |
} | |
requires { | |
int size(); | |
void add(ItemRecord item); | |
void remove(ItemRecord item); | |
} | |
stageprop Catalog { | |
public ItemRecord getItemRecordById(int id) { | |
return getById(id); | |
} | |
} | |
requires { | |
ItemRecord getById(int id) const; | |
} | |
/////////////////// | |
context BorrowItem { | |
public BorrowItem init(ItemRecord item) { | |
Item = item; | |
} | |
stageprop Item {} requires { | |
int id(); | |
//Question: should the ItemRecord include a property for the allowed loan duration, | |
//or should that be stored somewhere else? | |
} | |
public void borrow() { | |
Loan loan = new Loan(Borrower, Item); | |
//TODO validate and save to DB | |
} | |
} | |
} | |
class BorrowLibraryItemsController | |
{ | |
private InstructionsView instructionsView_; | |
private ItemsToBorrowView itemsToBorrowView_; | |
//... | |
public void init() { | |
instructionsView_ = new InstructionsView(this); | |
itemsToBorrowView_ = new ItemsToBorrowView(this); | |
//... | |
} | |
public InstructionsView instructionsView() const {return instructionsView_;} | |
public ItemsToBorrowView itemsToBorrowView() const {return itemsToBorrowView_;} | |
//... | |
} | |
class ItemRecordRepository { | |
public ItemRecord getById(int id) const { | |
//get the library item record from the database and return it | |
} | |
} | |
class MainController { | |
private User currentUser_; | |
/* | |
public void init() { | |
... | |
} | |
public boolean authenticate() { | |
... | |
} | |
*/ | |
public void borrowLibraryItems() { | |
new BorrowLibraryItems() | |
.init(currentUser_, new ItemRecordRepository()) | |
.start(); | |
} | |
} | |
{ | |
MainController controller = new MainController(); | |
controller.init(); | |
controller.borrowLibraryItems(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment