Skip to content

Instantly share code, notes, and snippets.

@alibenmessaoud
Created August 18, 2020 09:43
Show Gist options
  • Save alibenmessaoud/091cd96c4cc0fa99ba563b3d2d994c4f to your computer and use it in GitHub Desktop.
Save alibenmessaoud/091cd96c4cc0fa99ba563b3d2d994c4f to your computer and use it in GitHub Desktop.
class LoyaltyCardService {
// constructor removed for brevity's sake
void addPoints(int id, int points) {
LoyaltyCard card = //... find card by id in db
card.balance += points;
// persist the LoyaltyCard
}
void removePoints(int id, int points) {
LoyaltyCard card = //... find card by id in db
if (card.balance < points)
throw new Exception("Not enough points.");
card.balance -= points;
// persist the LoyaltyCard
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment