Vending Machine — Detailed
classDiagram
direction TB
class VendingMachine {
-inv: Inventory
-reg: CashRegister
-state: VMState
+select(slot)
+insertCash(c: Coin)
+cardPay(amount)
+cancel()
+dispense()
}
class VMState {
<<interface>>
+select(vm, slot)
+pay(vm, amount)
+cancel(vm)
+dispense(vm)
}
class IdleState
class SelectedState
class PaidState
class DispensingState
class OutOfServiceState
class Item {
+sku
+name
+price
}
class Inventory {
+stock: Map slot -> List Item
+reserve(slot)
+dispense(slot)
+reload(items)
}
class CashRegister {
-balance: Map Denom -> int
+acceptCoin(c)
+makeChange(amount) List~Coin~
+canMakeChange(amount) bool
}
class PaymentMethod {
<<interface>>
+pay(amount) bool
}
class CashPayment
class CardPayment
class UPIPayment
class Display
class CoinReturn
class Slot
VendingMachine --> VMState
VMState <|.. IdleState
VMState <|.. SelectedState
VMState <|.. PaidState
VMState <|.. DispensingState
VMState <|.. OutOfServiceState
VendingMachine *-- Inventory
VendingMachine *-- CashRegister
VendingMachine *-- Display
VendingMachine *-- CoinReturn
Inventory *-- "many" Slot
Slot *-- "many" Item
VendingMachine --> PaymentMethod
PaymentMethod <|.. CashPayment
PaymentMethod <|.. CardPayment
PaymentMethod <|.. UPIPayment
Glossary & fundamentals