Skip to content

Instantly share code, notes, and snippets.

@evrentan
Created December 19, 2021 17:45
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
A Separate Builder Class in order to be Used to Build the Class
package evrentan.examples;
public class PersonBuilder {
Person person = new Person();
public static PersonBuilder initialize() {return new PersonBuilder();}
public PersonBuilder withFirstName(String firstName) {
person.setFirstName(firstName);
return this;
}
public PersonBuilder withLastName(String lastName) {
person.setLastName(lastName);
return this;
}
public PersonBuilder withFullName(String firstName, String lastName) {
person.setFirstName(firstName);
person.setLastName(lastName);
return this;
}
public PersonBuilder withAge(Integer age) {
person.setAge(age);
return this;
}
public PersonBuilder withSex(String sex) {
person.setSex(sex);
return this;
}
public Person build() {return person;}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment