Vending Machine Modeling 2003 Fall Software Design (CSED332) Oct. 30th, 2003 Pohang University of Science and Technology (POSTECH) Copyright © 2003 SE Lab. Dept. of CSE POSTECH, R.O. Korea Agenda Domain Model Use Case Collaboration Diagram Design Class Diagram Message Sequence Diagram POSTECH Copyright © 2003 SE Lab. Dept. of CSE POSTECH, R.O. Korea Domain Model Vending Machine Domain Model modify Owner 1 1 1 1..* ItemSpec price add or remove item 1..* push SelectionButton 1..* 1 add or remove money notifyselection 1 1 * 1 * notifychangerequest 1 * 1 Insert coin 1 Insert bill 1 POSTECH Copyright © 2003 SE Lab. Dept. of CSE POSTECH, R.O. Korea CoinReceiver BillReceiver deposit-money-to 1 1 deposit-money-to 1 1 requestdispense turn-on or -off ItemDispenser 1 ItemLight 1 1..* Inform-total TransactionManagement total requestchangedispense 1 1 quantity 1 Customer * 1 ItemManagement Inform-deduction push ReturnButton 1 describes-item display-total-of 1 1 MoneyDisplay 1 add-money query-if-changeable 1 MoneyCounter c50_Count c100_Count c500_Count bill_Count 1 Requestdispense MoneyDispenser 1 Use Case Vending Machine Use Cases (1) Actors and their goal Owner - to fill items - to fill money - to change item (info.) Customer - to buy one or more drinks POSTECH Copyright © 2003 SE Lab. Dept. of CSE POSTECH, R.O. Korea Corresponding Use Cases - Fill Items - Fill Money - Change Items Customer - Buy Items Vending Machine Use Cases (2) Use Case Use Case: Buy Items Primary Actor: Customer Stakeholders: Tax Collector - interested in collecting correct sales tax Precondition: Vending Machine (VM) turned on, not in manager mode, and the numbers of each item contained in VM greater than zero. Post-condition: Customer gets one or more items and exact change. Main Success Scenario *1. Customer deposits money. *2. Customer selects an item. *3. Customer gets change. At any time, 1~3 can be repeated in arbitrary order. Term Definition and Information manager mode The mode that the vending machine turns into when the owner changes item information, fills money or items. selectable item If the following three conditions are met, the item is selectable. - The total amount of money is greater than or equal to the price of the item. - The difference between the total amount of money and the price of the item is changeable. - The quantity of the item contained in the VM is greater than zero. POSTECH Copyright © 2003 SE Lab. Dept. of CSE POSTECH, R.O. Korea Aliases Vending Machine Use Cases (3) Use Case Use Case: Deposit Money Primary Actor: Customer Precondition: Vending machine turned on, not in manager mode Post-condition: Total amount of money updated and item lights for selectable items are turned on. Main Success Scenario 1. Customer inserts a coin or bill. 2. Vending Machine (VM) updates display with the total amount deposited. 3. VM turns on item lights for selectable items. Extensions 1a. If an irregular coin or bill is inserted, the VM rejects it. POSTECH Copyright © 2003 SE Lab. Dept. of CSE POSTECH, R.O. Korea Vending Machine Use Cases (4) Use Case Use Case: Select an Item Primary Actor: Customer Precondition: Vending machine turned on, not in manager mode, and selectable items lighted Post-condition: Customer gets a selected item if s/he choose selectable one and the total amount of money is deducted by the price of the dispensed item. Main Success Scenario 1. Customer pushes a selection button. 2. If the item corresponds to the pushed button is selectable, VM dispenses the item and deduct total amount of money by the price of the item. 3. VM turns on item lights for selectable items and turns off item lights for not selectable items. POSTECH Copyright © 2003 SE Lab. Dept. of CSE POSTECH, R.O. Korea Vending Machine Use Cases (5) Use Case Use Case: Get Change Primary Actor: Customer Precondition: Vending machine turned on, not in manager mode Post-condition: User gets exact change. Total amount of money is updated to zero. Main Success Scenario 1. Customer push the button to get the change. 2. VM updates money display to zero. 3. VM turns off all item lights. 4. VM returns change. POSTECH Copyright © 2003 SE Lab. Dept. of CSE POSTECH, R.O. Korea Vending Machine Use Cases (6) Use Case Use Case: Fill Items Primary Actor: Owner Precondition: Vending machine turned on, not in use by the user Post-condition: Item refilled and item number updated Main Success Scenario 1. Owner opens the cover. 2. Owner fills items. 3. VM counts and updates item numbers. 4. Owner closes the cover. POSTECH Copyright © 2003 SE Lab. Dept. of CSE POSTECH, R.O. Korea Vending Machine Use Cases (7) Use Case Use Case: Fill Money Primary Actor: Owner Precondition: Vending machine turned on and not in use by the user Post-condition: Money refilled and the amount is updated Main Success Scenario 1. Owner opens the cover. 2. Owner fills coins and bills into money holders. 3. VM counts and updates money amount. 4. Owner closes the cover. POSTECH Copyright © 2003 SE Lab. Dept. of CSE POSTECH, R.O. Korea Vending Machine Use Cases (8) Use Case Use Case: Change Items Primary Actor: Owner Precondition: Vending machine turned on, not in use by the user Post-condition: Item price information changed Main Success Scenario 1. Owner opens the cover. 2. Owner sets new price for items. 3. Owner closes the cover. POSTECH Copyright © 2003 SE Lab. Dept. of CSE POSTECH, R.O. Korea Vending Machine SSD (1) :Customer System Sequence Diagram :System SSD1 – deposit money :System SSD2 – select an item :System SSD3 – get change inserts money( coin or bill ) Money display is updated. Item lights for selectable items are turned on. :Customer selects an item selected item dispensed Money display is updated. Item lights for selectable items are turned on. :Customer request change Money display is reset to zero. All item lights are turned off. change returned POSTECH Copyright © 2003 SE Lab. Dept. of CSE POSTECH, R.O. Korea System Sequence Diagram Vending Machine SSD (2) :Owner :System SSD4 – fill items :System SSD5 – fill money :System SSD6 – change items open cover fill items close cover :Owner open cover fill money close cover :Owner open cover modify item price close cover POSTECH Copyright © 2003 SE Lab. Dept. of CSE POSTECH, R.O. Korea Design Class Diagram Design Class Diagram of VM ItemSpec price: Integer PriceInputDevice SelectionButton 1 ItemRefillSensor setPrice 1 processSelection 1 setQuantity 1..* getPrice() setPrice( price ) 1 getPrice 1 ItemManagement 1 quantity: Integer 1 totalChanged( total ) setQuantity( num ) processSelection() ItemDispenser dispense() 1 dispense 1 turn-on turn-off 1..* totalChanged 1 TransactionManagement deduct, getTotal ReturnButton CoinReceiver BillReceiver 1 Copyright © 2003 SE Lab. Dept. of CSE POSTECH, R.O. Korea 1 1 deposit 1 total: Integer addMoney( amount ) deduct( amount ) getTotal() returnChange() 1 returnChange addMoney 1 deposit 1 MoneyRefillSensor 1..* POSTECH returnChange 1 setMoney 1 1 ItemLight 1 turnOn() turnOff() isChangeable display 1 MoneyDisplay 1 display(num) MoneyCounter c50_Count: Integer c100_Count: Integer c500_Count: Integer bill_Count: Integer isChangeable( amount ): Boolean deposit( amount ) setMoney( type, count ) returnChange( amount ) 1 dispense MoneyDispenser 1..* dispense( count ) Deposit Money POSTECH Copyright © 2003 SE Lab. Dept. of CSE POSTECH, R.O. Korea Message Sequence Diagram Select an Item POSTECH Copyright © 2003 SE Lab. Dept. of CSE POSTECH, R.O. Korea Message Sequence Diagram Get Change POSTECH Copyright © 2003 SE Lab. Dept. of CSE POSTECH, R.O. Korea Message Sequence Diagram Others Message Sequence Diagram MSD for Fill Items MSD for Fill Money MSD for Change Items POSTECH Copyright © 2003 SE Lab. Dept. of CSE POSTECH, R.O. Korea References • Craig Larman, Applying UML and Patterns 2nd Ed., 2001, PHPTR POSTECH Copyright © 2003 SE Lab. Dept. of CSE POSTECH, R.O. Korea