If a class extends a parent which defines an interface, should that class also explicitly implement the interface?
As an example, is it better to include or remove the portion in square brackets below:
interface IVerbable {}
abstract class BaseVerber implements IVerbable {}
class Verber extends BaseVerber [implements IVerbable] {}
Functionally, there is no difference in forced implementation, since Verber
"is-an" IVerbable
by virtue of it's parentage, even if it doesn't explicitly implement the interface itself:
var_dump(new Verber() instanceof IVerbable); // bool(true)
Non-functionally, there seem to be two benefits to implementing in both places:
- A person reading the code immediately knows that it implements the interface, without having to view the parent's definition.
- Second, PhpDocumentor doesn't follow the trail if the abstract class doesn't give a default implementation of the interface. The concrete implementation would not inherit the documentation unless either it explicitly implements the interface, or the abstract gives an implementation, even an empty one.
I suppose it might be bad practice to omit implemented methods from the abstract class though. It's probably better to at least show the empty signature, but then you're also just duplicating the empty signature in both the interface and the abstract class.