Loading...
VendingMachine:
Inventory
Payments
Transaction
ManagementService
CashStorage
Inventory
Map
addItem(item, count)
checkStock(String id)
removeItem(id)
addItem(id, count)
Payments:
Use Strategy pattern, create a PaymentStrategy Interface:
Use a factory class to create encapsulate the creation of the correct PaymentStrategy
Also need a Transaction Class to book keeping
ManagementService
public class VendingMachine{
private Inventory inventory;
private PaymentProcessor paymentProcessor;
private ManagementService managementService;
private TransactionCollector transaction;
private CashStorage cashStorage;
public boolean vendItem(String itemId, payType, amount);
}
public class Inventory { // singleten
private List<String, Item> items;
private List<String, Integer> stock;
Inventory getInstance();
void addNewItem(Item item, int stock);
boolean refill(String code, int stock);
int getStock(String code)
int sellItem(String item)
}
public class Item{
String code;
String name;
double price;
}
public PaymentProcessor {
PaymentStrategy paymentStrategy;
boolean pay(double amount);
}
public class CashPaymentStrategy implements PaymentProcessor
public class CoinPaymentStrategy implements PaymentProcessor
public class CardPaymentStrategy implements PaymentProcessor
public class PaymentFactory{
PaymentFactory createPaymentStrategy(PaymentType);
}
public enum PaymentType{
CASH,
COIN,
CARD
}
public class TransactionCollector {
List<Transaction> transactions;
addTransaction(Transaction);
getAll();
}
public class Transaction{
Datetime createdAt;
String ItemCode;
String ItemName;
String paymentType;
String amountPaid;
}
public class Alert{
String message;
Type ErroType;
Datetime createdAt;
}