There appears to be some contradictory information in this document.
An interface has the following properties:
An interface is like an abstract base class: any non-abstract type inheriting the interface must implement all its members.
But the c# spec says:
20.4.5 Abstract classes and interfaces
1. Like a non-abstract class, an abstract class must provide implementations
of all members of the interfaces that are listed in the base class list of
the class.
It seems contradictory, but it is not, quite.
The abstract class must provide a prototype for the interface's method, but is not required to provide a body.
So you may:
public interface IExample {
void Action();
}
public abstract class AbsExample : IExample {
abstract void Action(); // this is required for AbsExample to compile
}
Note that if you do it this way you may NOT explicitly implement the interface's methods- probably because a child class cannot override explicitly implemented interface methods. (I think?)
Therefore this does not compile:
public abstract class BrokenExample : IExample {
abstract void IExample.Action();
}
Because abstract is not a valid modifier for the explicitly-implemented method.
It remains unclear to me, however, why the abstract is required to implement the interface at all and cannot simply delegate that responsibility to its eventual descendants. After all, interfaces do this:
public interface IChild : IExample {
void Foo();
}
public class Burdened : IChild {
//Must implement both Action and Foo.
}
-- as do abstract classes that inherit from another abstract class- they pass down the implementation responsibility to the child.