3

I don't know if this is a best practices or not. If I have a interface that extends another interface such as :

public interface A extends B{
    public void something();
};

and a concrete class that implements A such as:

public class MyClass implements A {
    @Override 
    public void something(){
        System.out.println("ZOINKS");
    }

    @Override
    public void somethingFromB(){
        System.out.println("Hey, Scoobs!");
    }
};

Should I be adding B to the concrete class to identify the other interface?

1 Answer 1

3

A extends B means "A is a B". By implementing A, MyClass says "I'm a A, and therefore I'm B".

So, given the Java semantic, it's perfectly right to only (directly) implement the specialized interface. It's clear, and it avoids redundancy.

The only case where a redefinition could be interesting is when you use an interface as a marker (which is probably not such a good idea). It's simpler to get the interfaces directly implemented by a class rather than all the interfaces, including the inherited and extended ones.

Personally, I never 'redeclare' an implementation.

1
  • Thanks, this makes sense, Clarity it what I am going for. Commented Nov 17, 2015 at 15:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.