interface A {
void doSomethingA1();
void doSomethingA2();
void doSomethingA3();
}
interface B {
void doSomethingB();
A getA();
}
interface C {
void doSomethingC();
A getA();
}
interface X {
A getA();
B getB();
C getC();
void doSomethingX();
}
class AImpl implements A {
int x;
public void doSomethingA1() { /* ... */ }
public void doSomethingA2() { /* ... */ }
public void doSomethingA3() { /* ... */ }
}
class BImpl implements B {
A a;
public A getA() { return a; }
public void doSomethingB() { /* ... */ }
}
/* если нужно явно имплементировать А (без делегации)
class BImpl implements B, A {
public A getA() { return this; }
public void doSomethingA1() { }
public void doSomethingA2() { }
public void doSomethingA3() { }
public void doSomethingB() { }
}
*/
class CImpl implements C {
A a;
public A getA() { return a; }
public void doSomethingC() { /* ... */ }
}
class XImpl implements X {
B b;
C c;
public B getB() { return b; }
public C getC() { return c; }
// нужно явно разрешить diamong problem
public A getA() { return b.getA(); }
public void doSomethingX() { /* ... */ }
}
class Main {
public static void main
(String[] args
) { } void usage() {
X x = null; // createX(...)
x.doSomethingX();
x.getA().doSomethingA1();
x.getA().doSomethingA2();
x.getA().doSomethingA3();
x.getB().doSomethingB();
x.getC().doSomethingC();
}
}