Design patterns in software came from the work of the Gang of Four in the mid-1990’s. Similarly, TDD was first promoted around the same time in history as part of eXtreme Programming. Some have suggested that these two points of view stand in opposition to each other, saying
Design patterns are about up-front design, while TDD is about emerging design through the test-first process.
In truth, TDD and design patterns are highly synergistic. Understanding each of them contributes to your understanding of the other.
First, design patterns represent a focus on specific qualities in design. These very same qualities lead to greater testability, especially when creating the kinds of tests TDD requires. But also, each pattern can include in its collection of best practices the ideal way to test a given pattern, and again “ideal” in the sense that the tests empower TDD.
And finally, TDD includes refactoring the code as we go, and often the refactoring of the code leads to well-understood design patterns. If the team understands this it massively aids in collaboration.
TDD and design patterns work together because they value the same things.
Note: For each design pattern, the Net Objectives Pattern Repository describes the best way to test it. Have a look.
Note: For each design pattern, the Net Objectives Pattern Repository describes the best way to test it. Please have a look at www.netobjectives.net/PatternRepository.
This is Scott Bain. Visit us at www.netobjectives.com.