-
Improvement
-
Resolution: Done
-
Medium
-
None
-
None
Current Builders allow setting properties only as an entire field. This is ends up being clunky, as we really want them to be built in a fluent way.
This is especially problematic with Map-based properties, as populating the map requires the product to be present to extract the key:
Map<Bar> bars = ...; Bar tmp = new BarBuilder().setName("one").build(); bars.put(tmp.key(), tmp); tmp = new BarBuilder().setName("two").build(); bars.put(tmp.key(), tmp); Foo foo = new FooBuilder().setBar(bars).build();
with the empty/null equivalence, we can improve this to something like:
Foo foo = new FooBuilder() .addBar(new BarBuilder().setName("one").build()) .addBar(new BarBuilder().setName("two").build()) .build();
Since these methods are shifting backing structure maintenance to the builder, we also need to ensure proper encapsulation of copy mechanics.