views:

76

answers:

2

Hi all,

I am currently writing a wrapper library in C# that wraps a COM object that has a very small and painful to use API and am having a bit of problem with clutter.

This is the first project that I have used TDD and mocking on, so sorry if this isn't really a big problem. I gave a copy of my library to one of my work mates and the first thing that he noticed was the large amounts of interfaces that where in the API.

I explained to him that because I doing unit testing and mocking I needed the interfaces to stop the tests touching the COM object, he sort of understood but it got me thinking maybe my API is a little bit cluttered making it hard to understand.

My question is - If I am writing a wrapper library where every object touches the COM API somewhere, what is the best way to declutter my API and still be able to test the code.

Should I be using abstract classes insteed of interfeces for most things? or should I just hide the interfaces that are only for mocking reasons away in a namespace somewhere?

A: 

If an interface is there only for mocking purposes, I would suggest making it internal. You can then apply InternalsVisibleToAttribute to your wrapper library to expose the internal interfaces to your tests.

itowlson
+1  A: 

I haven't found having an exposed API to be a big deal beyond the comment to a coworker. Your coworker will appreciate the flexibility with which your application will change as you move forward way more than the "cluttered" API.

I wouldn't worry about it and move on with your life.

As for mocking, I definitely prefer interfaces over abstract classes. You'll find the more you go into this that you'll write composed applications instead of inherited ones. This is due to the fact that you want to keep your objects small and the dependencies few so the testing doesn't turn into a big mess.

Michael Hedgpeth