2 Builders, 1 Code? WithCRTP()
Did you ever copy-paste builder methods across similar builders and just accept it?
This is especially painful when creating multi-stage FluentAPIs, ones that only expose valid methods at each build step.
CRTP (Curiously recurring template pattern) eliminates this entirely.
It lets base classes return the concrete builder type instead of the abstract one.
Where this helped
I have benefitted greatly from this while creating FluentAPIs for Xcepto, my declarative testing framework.
Both the RestAdapter and the SsrAdapter builders require generic HTTP building methods like WithHTTPVerb(verb) and AddQueryParameter(key, value).
Without CRTP I would have had to implement it twice, violating Single-Source-Of-Truth and making the implementation prone to inconsistent changes.
Instead I moved them into an abstract HTTP builder base.
One source of truth. No duplication.
This is how I keep Xcepto’s builders consistent without duplication: