TDD by Example: Chapter 4 Privacy


The multiplication test is re-written to make it clear that sending the times message on an instance Dollar will return a new instance of Dollar. With this done, the instance variable amount can be made private.

The rest of the chapter is one paragraph about the nuance promise of TDD and the summary of what was done. TDD doesn't promise perfection, it lessens the chance of a defect to a low enough probability that we can move forward with confidence.


This short chapter says something important. TDD does not mean you won't make mistakes, all it does is lessen the chance that you will make a mistake. You first explicitly say what you want the code to do and then you see if it actually does it. You then see if you can improve the design while making sure the code still does what you want it to do. And when a mistake happens, it just means you now know the test you should have written, you can write it, get it to pass and move on.