This is a short chapter that completes the refactoring started somewhere
around chapter 5. The subclasses,
Franc, are nothing but constructors. It's time to remove
Dollar is not used anywhere and thus deleting
doesn't cause any test to fail.
Franc is used in the test
testDifferentClassEquality() which makes sure that
Money(10, "CHF") is equal to
Franc(10, "CHF"). This test is unnecessary since
equality is more than adequately covered in
testDifferentClassEquality() is deleted and some of the
testEquality() are also deleted since they are
not needed to verify equality.
This is the easy part after doing the hard work to make it easy. Delete
the subclasses, but first the delete the test that knew one of the
subclasses by name. He doesn't emphasize this, he doesn't
emphasize most of what can be learned from the book, but Beck gives us the
experience of how knowing the name of something is a form of coupling.
Because the test for equality knew the name of one of the subclasses of
Money we couldn't just delete the subclass even
though it was useless.
Beck also spent time cleaning up his tests after he cleaned up his code. We often focus what story the code tells, but maybe just as important is what story the test tell. A question worth asking: Do the tests express the intent of the code being tested?