TDD and the SOLID principles (Part 7 – Conclusion)

November 20, 2011

Table of contents:

Pat 1 – introduction

Part 2 – SRP

Part 3 – OCP

Part 4 – LSP

Part 5 – ISP

Part 6 – DIP

Part 7 – Conclusion (This post)

Often when talking about TDD it is said that despite of its name, TDD is not a testing methodology, but rather it’s a design methodology. As you’ve seen in this series of articles, the SOLID principles goes hand-in-hand with TDD, and indeed TDD drives the design of your code in a way that adheres to the SOLID principles. These principles ensured that each class in your code is loosely-coupled and reusable, which makes your application highly maintainable.

Even though you can write code that adheres to the SOLID principles, and also write unit tests for them in afterthought (not TDD), it is much more likely that you’ll get it right if you write the tests first, because the tests forces you to design your class to be isolatable, and thus reusable and loosely coupled.

In addition, the existence of well-written tests allows you to refactor your code much more easily and improve it to adhere to the SOLID principles even if they’re currently not 100% compliant.

Add comment
facebook linkedin twitter email

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*