java - POJO multiple-hierarchy Builder -


i'm trying achieve hierarchy of builder more 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 when call operation of super class it's returning builder of class. don't want duplicate setter method in each child, cause maybe contain logic.

i tried using generics not achieve in clean way.


Comments