tags:

views:

156

answers:

5

In my /interfaces folder I put all my interfaces.

Is an abstract class a type of interface?

+5  A: 

No. There are several differences. The main difference is that there can be implementation details in an abstract class. A class can only derive from one (abstract) class, but it can implement multiple interfaces. An abstract class can contains fields while an interface can not. Lastly, interfaces can not have access modifiers on the declared methods, but abstract classes can.

Jason
+7  A: 

In C#, interfaces are distinct from classes (even abstract classes);

  • interfaces can only define the API (method signatures, event declarations, property declarations), not the implementation (fields, method bodies, etc)
  • you can only inherit one base class, but you can implement multiple interfaces

But they have similarities in some usages - for example when used in an abstract factory implementation.

Marc Gravell
+2  A: 

No. An abstract class should include implementation of something, so it is more than just an interface.

Scott Saunders
+1  A: 

A class with all abstract methods could be viewed as a kind of interface, but, at that point why wouldn't you just use an interface instead?

Donnie
+8  A: 

The answers which describe the technical differences are correct, but there's more than that. There's also a semantic difference.

The difference between an interface and an abstract class is that an interface represents the ability to do something, whereas an abstract class represents the commonalities of a class of objects.

The IDisposable interface represents the concept "I know how to dispose of my important resources"; that's something the object can do, not something the object is.

By contrast, if you were to make an abstract class Animal, then that would represent the common features of all animals. There are no objects in the world that are "animal" without being some more specific kind of animal -- golden retriever, king salmon, lion, whatever. We represent this fact by making the class abstract.

Eric Lippert