Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

11. Designing for Test-Driven Development > Use Is Better Than Reuse

Use Is Better Than Reuse

Although many of the preceding design principles have put a lot of emphasis on creating classes that can be interchanged with different implementations or reused in multiple contexts, the first and most important factor to be sure of is that the class is needed in the single context of the app you’re trying to write before you even design the tests that exercise it.2

2. You could think of this as the Non-Zero Responsibility Principle.

Through the process of developing BrowseOverflow, I frequently referred back to the app’s requirements to see what was needed when designing a particular class or collection of classes. I wrote the app with the goal of satisfying these requirements, and although I looked for opportunities to reuse code within the context of the app (as with the example of BrowseOverflowViewController, which acts as the view controller for three separate views), I didn’t worry about generalizing the created classes beyond the app’s requirements. For example, the QuestionListTableDataSource is useful for displaying a list of Stack Overflow questions, and not for much else.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint