Chapter 8. Makin' Objects

$5 + 10 CHF = $10 if rate is 2:1$5 * 2 = $10Make “amount” privateDollar side effects?Money rounding?equals()hashCode()Equal nullEqual object5 CHF * 2 = 10 CHFDollar/Franc duplicationCommon equalsCommon timesCompare Francs to DollarsCurrency?

The two implementations of times() are remarkably similar:

Franc
					Franc times(int multiplier) {
   return new Franc(amount * multiplier);
					}
				
Dollar
					Dollar times(int multiplier) {
   return new Dollar(amount * multiplier);
					}
				

We can take a step toward reconciling them by making them both return a Money:

Franc
					Money times(int multiplier) {
   return new Franc(amount * multiplier);
					}
				
Dollar
					Money times(int multiplier) {
   return new Dollar(amount * multiplier); ...

Get Test Driven Development: By Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.