Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are interfaces used so prolifically in .NET apps?

Recently I began working on a largish mainstream project to deliver a public-facing e-commerce platform for a client I cannot reveal.

I'm working with seasoned developers with many years experience across many projects in the City of London.

It seems everyone is into interfaces in a big way. It's overwhelming and I now doubt everything I've done before, which is to use abstract base classes.

.NET is not COM, it's not an interface-based programming platform. Am I missing something or is this just herd mentality - the years of IProgramming have proliferated as accepted norms in .NET land?

Thanks

Luke

like image 564
Luke Puplett Avatar asked Feb 16 '11 09:02

Luke Puplett


1 Answers

Interfaces promote loose coupling, and are easy to mock. They make the separation between API and implementation very clear.

Of course, you can use abstract base classes when there'll be common functionality between different implementations (and there can still be an interface on top of the abstract class if you want) but if everything in the abstract class is abstract, and there are no fields, why use up your one shot at inheritance by way of an abstract class? Where's the benefit?

like image 200
Jon Skeet Avatar answered Oct 13 '22 22:10

Jon Skeet