core-java icon indicating copy to clipboard operation
core-java copied to clipboard

Unify the API of hand-written `Builder`s

Open armiol opened this issue 5 years ago • 0 comments

The framework uses the Builder pattern to create complex Java objects such as Delivery.

However, the naming of getters and setters varies from time to time. We need to review the code throughout the repository and unify the naming approach.

The proposal is as follows.

FooBar.Builder builder = FooBar.newBuilder();
builder
    .setTheExpectation(myExpectation);     // setter naming

// Check whether the value has been set.
if(builder.hasTheExpectation()) {    

    // Throws NPE if not set.
    TheExpectation justSet = builder.getTheExpectation(); 
}

We could then automate the Builder testing using Java reflection.

armiol avatar Feb 13 '20 16:02 armiol