Interfaces and abstract class inheritance, implementation in extended classes

Dan Lugg picture Dan Lugg · Jun 16, 2011 · Viewed 19.8k times · Source

In every example I've seen, extended classes implement the interfaces of their parents. For reference, the following example:

interface MyInterface{
    public function foo();
    public function bar();
}

abstract class MyAbstract implements MyInterface{
    public function foo(){ /* stuff */ }
    public function bar(){ /* stuff */ }
}

// what i usually see
class MyClass extends MyAbstract implements MyInterface{}

// what i'm curious about
class MyOtherClass extends MyAbstract{}

Is failure to implement an interface in a child, which is implemented by a parent, considered bad practice or something? Are there any technical drawbacks to omitting the implementation in the child?

Answer

Emil Ivanov picture Emil Ivanov · Jun 16, 2011

I would consider that you are on the right path. There is no need to declare that you are implementing the interface, when extending a class that already implements it. For me it's just another piece of code to maintain if change is needed. So, yes, you are correct!