Each has its own purpose. You use an interface when you don't want to define any specific implementation. It only provides an "interface" to an object, that is the methods and properties that make up a public definition. An object can inherit multiple interfaces. A good example of this is the List<>
object. List<>
implements several interfaces, such as IEnumerable
, IList
, ICollection
, IEnumerable<>
, IList<>
, and ICollection<>
.
Each of these has different methods, and different properties, and are used for different purposes. You could not do this with an abstract class. You can cast a List<>
to any of those interfaces and use them without knowing the exact implemenation of them. This is particularly useful with a concept known as Dependency Injection, but has many other uses.
An abstract class is useful when you want to define part of the implementation of an object, but want to leave other parts up to the derived class. One key thing to remember about abstract classes is that they cannot be instantiated by themselves, because they typically lack a complete implementation as well as the fact that abstract keyword tells the complier it can't be instantiated. Yes, you can supply dummy implementations, but why? The whole point is that abstracts are.. well.. abstract.
Imagine you have a class Cat, and this class derives from a class Animal. There is no such thing as an Animal object, it's just a "type". You can't instantiate an Animal because there is no actual Animal in the real world, there are only creatures that are of the type Animal. You can treat different creatures as a common Animal type, but there can't exist a real Animal, it's just a concept.
An Animal would be an abstract type, because the concept of the Animal is abstract. The same is true in software. You might have the concept of an object, such as a Stream. Is it a NetworkStream? A FileStream? A MemoryStream? Stream is just a concept. An interface is also just a concept, but the unlike an abstract class an Interface cannot have any implementation.
So think of an abstract class as a concept with some implementation, and an interface as a concept without any implementation.