L
Lew
Mike said:Simpler than that: a class C which extends Foo will fail to load if
Foo is an interface.
The salient point is that when one writes an API, which comprises every class
a programmer writes except the top-layer invocation class, one has to plan
ahead for the maintenance needs of that API. Once released into the wild, the
contract of the API is a commitment and further changes have to be made
responsibly. The decision to implement a type as an interface or a class will
have to be honored through the useful life of that type, or the cost of a
change must be incurred. By exposing the type as an interface, one keeps
certain options open.
As usual, and as pointed out by many in this forum, that doesn't mean *always*
select interfaces as the exposed type or *never* do so with abstract classes.
It does mean understand the tradeoffs, and that generally interfaces are the
safer, cleaner choice.