views:

86

answers:

2

From a design and loose coupling standpoint. Is it a good idea to have an interface for each class in a project that might be part of a composition model?

I have a project where I'm doing this, but now I'm getting rather a lot of interfaces, in an attempt to keep things relatively loosely coupled.

+5  A: 

Without knowing specifics of your design, that's how the Interface Segregation Principle (pdf) is supposed to work.

You should provide an interface for every class that you may need to swap out the implementation for (I wouldn't create an interface for each DTO, for example).

Oded
+1  A: 

I generally create interfaces to loosely couple classes for testing so that I can create fakes for the classes I'm not interested in testing. EG a business logic manager class will have a reference to an interface for a data access class.

I only create an interface if I actually need a 'seam' for my tests, I don't just create interfaces for everything.

Charlie