We are kind of used to having builders like
A john = new BuilderForClassA().withName("John").withGenter("m").withDog("Muhtar").build();
Something like that.
Now imagine
class B extends A
...
and we want
BuilderForClassB extends BuilderForClassA
,
and we want
B mary = new BuilderForClassB().withName("Mary").withGender("f").withGod("Jesus").build();
And of course we want to reuse all those
BuilderForClassA
methods.
The problem is that they all look like
BuilderForClassA withName(String name) {
instance.setName(name);
return this;
}
So that after calling
withName("Mary")
we have no way to call
withGod("Jesus")
.
Any solution?