Search code examples
c#loose-coupling

Interfaces and Coupling


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.


Solution

  • 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).