Created
December 12, 2011 12:52
-
-
Save juliano/1467017 to your computer and use it in GitHub Desktop.
Builder imutável
This file contains 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 final class PersonImmutableBuilder { | |
private final String name; | |
private final String cpf; | |
public PersonImmutableBuilder() { | |
this(null, null); | |
} | |
private PersonImmutableBuilder(final String name, final String cpf) { | |
this.name = name; | |
this.cpf = cpf; | |
} | |
public PersonImmutableBuilder withName(final String name) { | |
return new PersonImmutableBuilder(name, this.cpf); | |
} | |
public PersonImmutableBuilder withCpf(final String cpf) { | |
return new PersonImmutableBuilder(this.name, cpf); | |
} | |
public Person build() { | |
return new Person(name, cpf); | |
} | |
public class Person { | |
private final String name; | |
private final String cpf; | |
private Person(final String name, final String cpf) { | |
this.name = name; | |
this.cpf = cpf; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment