I followed this example to create a build pattern with inheritance, but in the child classes I have common fields that I would like to have in a separate class.
BaseConfiguration
String attr1
|
/ \
/ \
/ \
/ \
/ \
AConfiguration BConfiguration
String x String y
| |
| |
| |
PersonalConfiguration ExternalConfiguration
int a (common) int a (common)
int b (common) int b (common)
String myCustom String other
getAttr1() <-inherited-> getAttr1()
getX() <-inherited-> getY()
And I would have (without interfaces):
BaseConfiguration
String attr1
|
/ \
/ \
/ \
/ \
/ \
AConfiguration BConfiguration
String x String y
\ /
\ /
\ /
CommonConfiguration
int a
int b
|
/ \
/ \
/ \
/ \
/ \
PersonalConfiguration ExternalConfiguration
String myCustom String other
getA() <-inherited-> getA()
getB() <-inherited-> getB()
getAttr1() <-inherited-> getAttr1()
getX() <-inherited-> getY()
The idea is use an interface:
public interface MyInterface<T, U extends BaseConfiguration> {
T build(final U baseConfiguration);
}
I am not sure if this is possible, or if it is possible by generalizing the CommonConfiguration
class (CommonConfiguration<T>
). I have not been able to