Proposal: Deprecate Builders

Richard Bair richard.bair at oracle.com
Tue Mar 26 00:07:27 PDT 2013


> Since I do not develop frameworks much, all these problems are not familiar to me, so probably your experience is much more insightful. Suppose the following steps:
> 1. create a AbstractClass of every end node and let the end node extend that: Node extens AbstractNode<Node>
> 2. use a one time pass over all classes to add a wither method for each setter (this is not something that is done on every build).
> 
> That would result in the following example class hierarchy. Let's also assume an interface NewNode2 with default methods having been added to Node:
> 
> abstract class AbstractNode<T> implements NewNode2<T> {
> 
>    final public void setName(String v) { ... }
> 
>    final public T withName(String v) {
>        setName(v);
>        return (T)this;
>    }
> }
> 
> Node extends AbstractNode<Node>{
>    ...
> }
> 
> Region extends AbstractRegion<Region> {
>    ...
> }
> 
> AbstractRegion<T> extends AbstractParent<T> {
>    ...
> }
> 
> AbstractParent<T> extends AbstractNode<T> {
>    ...
> }
> 
> interface NewNode2<T> {
> 
>    final public void setDescription(String v)  default { ... }
> 
>    final public T withDescription(String v) default {
>        setDescription(v);
>        return (T)this;
>    }
> }
> 
> 
> How would this hold up?

I don't know, I'm not a language expert either, I'd have to try it out and see :-). However it does look like it is just pushing bits around w.r.t. builders. That is, it introduced a new Abstract class per concrete type, and the withers are basically like the methods we had. So even in the best case where it solves the problems, we still have a lot of additional classes in the hierarchy.

The way to try out the compatibility issues is to just have two projects -- one with a minimal hierarchy (A and B is sufficient where B extends A). The other project just has a main method which creates an instance of B and initializes it. Then make various changes to the A / B API and try running the main project unmodified (i.e.: not recompiled) and see what happens!

Richard


More information about the openjfx-dev mailing list