I inherited some legacy Java (1.4) code and this design decision appears regularly. I can’t understand if there’s any purpose or reason to it.
public interface SoapFacade extends iConfigurable{ }
public class SoapFacadeBase implements SoapFacade{
...
}
public class SoapFacadeImpl extends SoapFacadeBase implements SoapFacade{
...
}
As I understand interfaces (and my experimentation has reinforced), there is no purpose to having both the parent and the child implement the same interface. In this scenario, everything from SoapFacade is implemented in SoapFacadeBase, but the method in iConfigurable is implemented in SoapFacadeImpl. However, that doesn’t create a need to have SoapFacadeImpl implement SoapFacade.
Is there something I don’t know about interfaces that would give this pattern some purpose or benefit? Are there underlying costs beyond lack of clarity that should drive refactoring it? Or should it simply be refactored for clarity/simplicity?
No. Technically, it is completely redundant.
It does however document the fact that you intend
SoapFacadeImplto be aSoapFacadeand it ensures that you get a compile error, if you (or someone else) decides to removeimplements SoapFacadefrom the base class.You see this pattern everywhere in the standard Java Collections API.
ArrayListimplementsListeven though its base class (AbstractList) already, does. Same holds forHashSet/AbstractSetand theSetinterface.