Skip to content

Commit

Permalink
Document how to create a "step builder" with AutoValue.
Browse files Browse the repository at this point in the history
Fixes #1000.

RELNOTES=n/a
PiperOrigin-RevId: 361656440
  • Loading branch information
eamonnmcmanus authored and Google Java Core Libraries committed Mar 8, 2021
1 parent 2f1cef9 commit 984e893
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions value/userguide/builders-howto.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ How do I...
* ... [offer **both** accumulation and set-at-once methods for the same
collection-valued property?](#collection_both)
* ... [access nested builders while building?](#nested_builders)
* ... [create a "step builder"?](#step)

## <a name="beans"></a>... use (or not use) `set` prefixes?

Expand Down Expand Up @@ -616,4 +617,14 @@ If `speciesBuilder()` is never called then the final `species()` property will
be set as if by `speciesBuilder().build()`. In the example, that would result
in an exception because the required properties of `Species` have not been set.

## <a name="step"></a>... create a "step builder"?

A [_step builder_](http://rdafbn.blogspot.com/2012/07/step-builder-pattern_28.html)
is a collection of builder interfaces that take you step by step through the
setting of each of a list of required properties. We think that these are a nice
idea in principle but not necessarily in practice. Regardless, if you want to
use AutoValue to implement a step builder,
[this example](https://github.com/google/auto/issues/1000#issuecomment-792875738)
shows you how.

[protobuf]: https://developers.google.com/protocol-buffers/docs/reference/java-generated#builders

0 comments on commit 984e893

Please sign in to comment.