When to TDD an Interface

Note: Cross posted from The Typemock Insider Blog.


Brett Schuchert, on the Object Mentor blog, writes about TDDing an interface.  One of the main questions raised is when to decide you need an interface rather than a concrete class.

The more I think about it, it comes back to your knowledge of the system. If the interfaces already exist, there’s no problem, you go with what you have. If not, then my experience tells me to with a concrete class. I leave extraction of interfaces to the refactoring phase.

Now, what does that mean?  There’s no refactoring phase in software development (not the one you tell yourself you’ll get to sometime). The refactoring phase in TDD, is when you leave time for thinking about the code. This is where you put 2 and 2 together, and say: Hey, doesn’t this behave like component X? This is the time to extract the interface. Or move up, any kind of refactoring.

And if you want to get there even earlier, you should do it in pairs. When you put two minds together, one of the advantages is that together, they know the system better. So chances are you’ll identify commonality earlier.

Leave A Reply

Your email address will not be published. Required fields are marked *