Last active
November 10, 2015 14:13
-
-
Save jalex19100/de7489ed1888f7522f9f to your computer and use it in GitHub Desktop.
My Preferred Builder Style - subtle and sweet. Unit testing friendly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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