Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 the MutableBuilder 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).

share|improve this question
The RootObject interface has no variables. How are you going to find a MutableBuilder object? – eric w Mar 21 '13 at 8:29
You might want to have a read of this: Always keep it simple. – Gary Rowe Mar 21 '13 at 10:50
@ericw: Probably the question is not really clear but I am trying for fun to develop a little framework, all the objects are going to be implemented by client code. RootObject has no variables because it is an Interface. – Andrea Richiardi Mar 21 '13 at 13:43
By the way I solved this by making the user explicitly passing Builder objects to the framework. The whole point was to detect the presence of inner MutableBuilder subclasses in the definition so that the framework could call build() and automatically create instances of the outer one. – Andrea Richiardi Jan 15 '14 at 2:02

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.