So to sum up, here is your class hierarchies:
package common;
public interface A
{
void doStuff();
}
package commom.impl;
public class B implements A
{
void doStuff() {}
}
package real.service;
public class D
{
void doSomeRealStuff() {}
}
package real.service;
public class C extends D
{
void doSomeRealStuffForGood() {}
}
Assuming that each class is declared in its own source file.
Just to recall from the OP, I assume you need B
stuff in C
and not really A
stuff. Because A
is nothing but a contract and you need then the real implemting class to be fetched inside your C
class in order to call the declared methods on.
In such a case, you may need to use the Inversion of Responsability approach, so that you declare an instacne of type B
inside your C
clas then you layer each method from B
with a one having the same signature and that do nothing but delegate the real call to the instance member:
package real.service;
import common.A;
import common.impl.B;
public class C extends D
{
private A delegate;
public C ()
{
delegate = new B();
}
void doStuff() {
delegate.doStuff(); // Call the real delegate method when doStuff is called on an isntance of C.
}
void doSomeRealStuffForGood() {}
}
Note that this is a legal OO concept, since you are following an HAS-a even though some could consider it a high coupling.
Otherwise if you are not tied to the B
class, and you may drop the declare methods in there for some others, you can declare an inner class that implements the A
interface the way you need.
Edit:
Java does not support multiple inheritance, though you have provided a common contract in your A
interface, so if you need all those methods (behavior) to be availble in your C
class, it would be better to implement it directely and override all the interface methods.