Skip to content

Instantly share code, notes, and snippets.

@evrentan
Created December 19, 2021 17:45
Show Gist options
  • Save evrentan/2e36404c56e9b0a4aae0730dfe20a484 to your computer and use it in GitHub Desktop.
Save evrentan/2e36404c56e9b0a4aae0730dfe20a484 to your computer and use it in GitHub Desktop.
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