第十三章 万恶之源(The Root of All Evil)——去除多余子类!
1、存在的问题:
(1)汇率转换问题,当汇率为2:1时,5美元 + 10法郎 = 10美元;
(5)钱数为整数;
(7)实现hashCode()函数;
(8)与空对象判等;
(9)与非同类对象判等;
(11)Dollar与Franc之间的重复设计问题;
2、同步工程实践:
去除子类Dollar和Franc:
package garbage;
public class Money {
protected int amount = 0;
protected String currancy;
public Money(int amount, String currancy) {
this.amount = amount;
this.currancy = currancy;
}
public static Money dollar(int amount) {
return new Money(amount,"USD");
}
public static Money franc(int amount) {