Skip to content

Instantly share code, notes, and snippets.

@pawelpluta
Created January 29, 2021 19:43
Show Gist options
  • Save pawelpluta/8841abef0d0f6f1f26725ed509aa61e5 to your computer and use it in GitHub Desktop.
Save pawelpluta/8841abef0d0f6f1f26725ed509aa61e5 to your computer and use it in GitHub Desktop.
Tell don't ask - sales
public class Sales {
private final CrateRepository crateRepository;
private final DeliveryService deliveryService;
public Sales(CrateRepository crateRepository, DeliveryService deliveryService) {
this.crateRepository = crateRepository;
this.deliveryService = deliveryService;
}
public boolean sell(Integer soldCrates, ProductType type, Customer customer) {
List<Crate> crates = crateRepository.findByTypeLimit(type, soldCrates);
if (crates.size() != soldCrates) {
return false;
}
if (customer.getWarehouseAddressVerified()) {
Package packageToDeliver = new Package(crates, customer);
deliveryService.send(packageToDeliver);
crateRepository.delete(crates);
return true;
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment