I see this too often on github and I fail to see the advantages, and even, use of interfaces in these relations.
Situation: A library has a base class Article which is declared abstract and is supposed to be extended. Why does it implement ArticleInterface which is basically:
interface ArticleInterface
{
// some getter
// some setter
// getter...
// setter....
// etc...
}
I don’t see the use of Interface in this setup? Isn’t abstract class by itself sufficient as it already has those getters/setters and properties defined (it implements the interface). Only thing Interface does here is force property declaration which isn’t supposed to be the point of it, right?
Interfaces make classes even more flexible. In the end, it really is the interface you want to define. An abstract class allows you to define some important parts of a classes interface and also (some of) the implementation. An interface is even more abstract, defining only the interface of the necessary functionality and leaving the implementation up to the implementer entirely.
You should think about it this way: the interface is the definition, the abstract class is merely an example implementation of it. If this skeleton implementation is suitable for your purposes, extend it and use it. Otherwise, if you cannot or don’t want to inherit a specific class, you can implement the interface any way you want. You’re not forced to extend a specific class, you can use your own class hierarchy.
For more information on why you should think in interfaces and why decoupling is rather important, you may want to read this article.