Skip to content

Instantly share code, notes, and snippets.

@jasongorman
Last active December 30, 2020 10:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasongorman/dbc56be32c43631e9a4952bce53e48d0 to your computer and use it in GitHub Desktop.
Save jasongorman/dbc56be32c43631e9a4952bce53e48d0 to your computer and use it in GitHub Desktop.
public class StockMonitor {
private final Alert alert;
private final Warehouse warehouse;
private final ReorderLevel reorderLevel;
public StockMonitor(Alert alert, Warehouse warehouse, ReorderLevel reorderLevel) {
this.alert = alert;
this.warehouse = warehouse;
this.reorderLevel = reorderLevel;
}
public void productSold(int productId, int quantity) {
Product product = warehouse.fetchProduct(productId);
if(needsReordering(product, quantity))
alert.send(product);
}
private Boolean needsReordering(Product product, int quantitySold) {
return product.getStock() - quantitySold <= reorderLevel.calculate(product);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment