Can CRC Cards Fit with TDD?
While CRC cards are lightweight, do they add any value if you practice test-driven development? If you practice TDD, you drive out implementation details by writing tests. You don’t write an inch of production code without writing a test for it first. You repeat many test-code-refine cycles during a day. Your design intent is expressed through tests. The act of writing tests helps you think through what your code should do. It is hard to separate designing from programming. Design thinking often happens between the keystrokes as you decide on the next test to write.
While many developers equate CRC cards with upfront design (not big upfront design, but still upfront design with coding to follow later), I’ll argue that this need not be the case. Nothing prevents you from integrating CRC cards with testing and coding. Think of a CRC card as the moral equivalent of a “back of the napkin” design sketch. That sketch is successively refined and tweaked as you write tests and code. Whether you jot down your initial ideas on a card, or scrawl high-level responsibility statements on a whiteboard or sticky notes is irrelevant. Sometimes just spending a couple of minutes sketching out an idea helps clarify your thinking before you turn to programming. Of course tests and code will flesh out that your ideas and make them real.
But if are a true master developer who prefers to see your design emerge from tests that drive your code, don’t bother with CRC cards. Don’t do anything that slows you down or add value. CRC cards don’t add value if you are already productively cranking out code without them.
But don’t summarily dismiss CRC cards as totally irrelevant, if lightweight distractions, either.
Sometimes even the most ardent coder needs to hit the pause button. Perhaps you need to bring others into a design discussion. Maybe you need to tackle a significant design challenge. You might need to consider several design alternatives or undertake a major refactoring. Or you simply might want to explain how a several objects work to a newcomer. In any of these cases, CRC cards or CRC card equivalents can help you think, explain, and explore essential design ideas. There’s always code and tests to back them up.