I hope I picked the right group for this question...
I have this little framework I want to implement and I would like to have an opinion on it. In particular I am more concerned about the succinctness and style of the solution. My class sketch looks like this:
public interface Builder<T> {
T build();
}
public interface RootObject {
public static abstract class MutableBuilder<T> implements Builder<T> {
protected MutableBuilder() { }
protected abstract void setA(A a);
protected abstract void setB(B b);
protected abstract void setC(C c);
protected abstract void setD(D d);
}
}
The goal is to have a Builder which returns an instance of (hopefully) immutable objects. The whole implementation is left to the client code, but I still want to give the imprinting of the Effective Java's fluent interface.
If it was just for this, I would not be that puzzled. The problem comes into lay when I add the requirements:
- the framework needs to reflectively search through a generic
RootObject
implementation in order to find if theMutableBuilder
static inner class has been implemented. - if found, the framework instantiates one or more
MutableBuilder
dynamically (that is the reason why I have an abstract class with a constructor and return it or them to the client code.
The mere talking about reflection makes me wonder if I am doing the right thing. It looks a reasonable solution to me (of course).