I'm trying to achieve a hierarchy of builder with more than 3 levels.
Something like:
public abstract class ElementBuilder {
protected String name;
public ElementBuilder setName(String name) {
this.name = name;
return this;
}
}
public abstract class OperationBuilder extends ElementBuilder {
protected String attribute;
public OperationBuilder setName(String attribute) {
this.attribute = attribute;
return this;
}
}
public abstract class FilterBuilder extends OperationBuilder {
....
}
The problem is that when I call an operation of the super class it's returning a builder of the that class. I don't want to duplicate the setter method in each child, cause it maybe contain some logic.
I tried using generics but I could not achieve it in a clean way.