Skip to content

Commit

Permalink
[#3] Refactor, pull reduced() as interface method and impl it in Money
Browse files Browse the repository at this point in the history
  • Loading branch information
EthanLin-TWer committed Jan 14, 2017
1 parent 9081fe0 commit 5ff4462
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
public class Bank {
public Money reduced(Expression money, String toCurrency) {
// TODO: [Linesh][1/9/17] Is type cast a bad smell?
if (money instanceof Money) return (Money) money;
if (money instanceof Money) return money.reduced(toCurrency);
Sum sum = (Sum) money;
return sum.reduced(toCurrency);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

public interface Expression {
Expression plus(Money money);

Money reduced(String currency);
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,9 @@ public Money times(int multiplier) {
public Expression plus(Money addend) {
return new Sum(this, addend);
}

@Override
public Money reduced(String currency) {
return this;
}
}

0 comments on commit 5ff4462

Please sign in to comment.