Skip to content

Instantly share code, notes, and snippets.

@JRobsonJr
Created September 10, 2018 22:49
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 JRobsonJr/197c821b68207f44a561f9664049306b to your computer and use it in GitHub Desktop.
Save JRobsonJr/197c821b68207f44a561f9664049306b to your computer and use it in GitHub Desktop.
Refactoring
// ...
private void substractWithDiscount(final Money money, int discount) {
account.substract(Money.newInstance(
money.getAmount() + money.getAmount() * account.overdraftFee() * discount,
money.getCurrency()));
}
@Override
public void withdraw(final Money money) {
if (account.isOverdraft) {
if (account.getType().isPremium()) {
substractWithDiscount(money, companyOverdraftDiscount / 2);
} else {
substractWithDiscount(money, companyOverdraftDiscount);
}
} else {
account.substract(Money.newInstance(money.getAmount(), money.getCurrency()));
}
}
// ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment