Skip to content

Instantly share code, notes, and snippets.

@jalex19100
Last active November 10, 2015 14:13
Show Gist options
  • Select an option

  • Save jalex19100/de7489ed1888f7522f9f to your computer and use it in GitHub Desktop.

Select an option

Save jalex19100/de7489ed1888f7522f9f to your computer and use it in GitHub Desktop.
My Preferred Builder Style - subtle and sweet. Unit testing friendly.
public class PreferredBuilder {
private String a;
private int i;
public PreferredBuilder() {
}
public PreferredBuilder(Builder builder) {
this.a = builder.a;
this.i = builder.i;
}
public String getA() {
return a;
}
public void setA(final String a) {
this.a = a;
}
public int getI() {
return i;
}
public void setI(final int i) {
this.i = i;
}
public static class Builder<T extends Builder> {
private String a;
private int i;
public Builder clear () {
a = null;
i = 0;
return this;
}
public Builder a(final String a) {
this.a = a;
return this;
}
public Builder i(final int i) {
this.i = i;
return this;
}
public BilledUsage build() {
return new BilledUsage(this);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment