mardi 10 décembre 2019

Can we have multiple build methods in our Builder Class?

I have a builder class for some object which has a method build

    static final class Builder {

            private Object o = new Object();


            public Object build() {
                o.initialize();

                Object tmp = o;
                o = null;

                return tmp;
            }

        //some setters

}

The code in initialize method does some initialization for the object, now I want to do some different initialization steps based on the setters, should I make another build method for different initialization steps?

Aucun commentaire:

Enregistrer un commentaire