I have a class builder that is responsible for returning an object it builds:
public class ObjetoBuilder {
private Objeto objeto;
public ObjetoBuilder() {
objeto = new Objeto();
}
public ObjetoBuilder adicionarId(Long id) {
if (id != null) objeto.setId(id);
return this;
}
public Objeto constroi() {
return objeto;
}
}
Doubt
Is it a good practice to have more than one build method in a builder ? For example:
public class ObjetoBuilder {
...
public Objeto controi() {
return objeto;
}
public List<Objeto> constroiLista(){
return Arrays.asList(objeto);
}
public String constroiJson() {
return new Gson().toJson(objeto);
}
public String controiXml() {
return new XStream().toXML(objeto);
}
}