-
-
Save jasongorman/dbc56be32c43631e9a4952bce53e48d0 to your computer and use it in GitHub Desktop.
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
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