O'Reilly logo

Test Driven Development: By Example by Kent Beck

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 10. Interesting Times

$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?Delete testFrancMultiplication?

When we are done with this chapter, we will have a single class to represent Money. The two implementations of times() are close, but not identical:

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

There's no obvious way to make them identical. Sometimes you have to go backward to go forward, a little like solving ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required