2.5. Design and Test Driven Development

As we've said, TDD is not about testing; it's more of a design technique. But how can writing tests before you write the code encourage a good design? Simply taking the time to stop and think before you write code can have a huge impact on the design of a system. This leads to an important question: what is a good design?

Well-designed software is the subject of many different books. However, we follow a core set of concepts focused on the SOLID principles outlined by Robert Martin (a.k.a. Uncle Bob). SOLID is a set of five principles based on the best practices for object-oriented development.

The SOLID design principles started as a reply to a 1995 newsgroup thread entitled "The Ten Commandments of OO Programming." This reply was formed by Robert Martin (Uncle Bob), and has become a great set of standards that many developers follow.

The principles encompassed in SOLID have been around for years, but many developers tend to ignore these principles that have been proven to aid in creating great software.

2.5.1. S — The Single Responsibility Principle

"There should never be more than one reason for a class to change."

—— Robert Martin (Uncle Bob) http://www.objectmentor.com/resources/articles/srp.pdf

The first principle defined in SOLID is that each class should have a single responsibility. A responsibility is defined here as being a reason to change. If a class has multiple responsibilities, then there are multiple reasons why it could ...

Get Testing ASP.NET Web Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.