A Separate Builder Class in order to be Used to Build the Class
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
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