/**
* This is what you have
*/
interface IXR {
//bla-bla-bla
}
class CXR implements IXR {
//concrete implementation of bla-bla-bla
}
interface IX {
public IXR f();
}
interface IYR {
//some other bla-bla-bla
}
class CYR implements IYR {
//concrete implementation of the some other bla-bla-bla
}
interface IY {
public IYR f();
}
/**
* This is what you need to add
*/
interface IZR extends IXR, IYR {
//EMPTY INTERFACE
}
class CZXR extends CXR implements IZR {
//EMPTY CLASS
}
class CZYR extends CYR implements IZR {
//EMPTY CLASS
}
class CZ implements IX, IY
{
public static boolean someCondition = true;
public IXR implementationOf_X_f()
{
System.out.println("CXR");
return new CZXR();
}
public IYR implementationOf_Y_f()
{
System.out.println("CYR");
return new CZYR();
}
public IZR f() {
if (someCondition) {
return (IZR) implementationOf_X_f();
} else {
return (IZR) implementationOf_Y_f();
}
}
}
/**
* This is the usage of the required class
*/
class program
{
public static void main(String[] x) {
CZ o = new CZ();
IZR r = o.f();
if (CZ.someCondition) {
CXR xr = (CXR) r;
//bla-bla-bla
} else {
CYR yr = (CYR) r;
//bla-bla-bla
}
}
} /**
* This is what you have
*/
interface IXR {
//bla-bla-bla
}
class CXR implements IXR {
//concrete implementation of bla-bla-bla
}
interface IX {
public IXR f();
}
interface IYR {
//some other bla-bla-bla
}
class CYR implements IYR {
//concrete implementation of the some other bla-bla-bla
}
interface IY {
public IYR f();
}
/**
* This is what you need to add
*/
interface IZR extends IXR, IYR {
//EMPTY INTERFACE
}
class CZXR extends CXR implements IZR {
//EMPTY CLASS
}
class CZYR extends CYR implements IZR {
//EMPTY CLASS
}
class CZ implements IX, IY
{
public static boolean someCondition = true;
public IXR implementationOf_X_f()
{
System.out.println("CXR");
return new CZXR();
}
public IYR implementationOf_Y_f()
{
System.out.println("CYR");
return new CZYR();
}
public IZR f() {
if (someCondition) {
return (IZR) implementationOf_X_f();
} else {
return (IZR) implementationOf_Y_f();
}
}
}
/**
* This is the usage of the required class
*/
class program
{
public static void main(String[] x) {
CZ o = new CZ();
IZR r = o.f();
if (CZ.someCondition) {
CXR xr = (CXR) r;
//bla-bla-bla
} else {
CYR yr = (CYR) r;
//bla-bla-bla
}
}
}