Skip to content

Instantly share code, notes, and snippets.

@5AbhishekSaxena
Created June 5, 2023 09:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 5AbhishekSaxena/67d8312fcb57591cc2e27d298f3ae24a to your computer and use it in GitHub Desktop.
Save 5AbhishekSaxena/67d8312fcb57591cc2e27d298f3ae24a to your computer and use it in GitHub Desktop.
class User private constructor(
val firstName: String,
val middleName: String?, // optional
val lastName: String,
val address: Address,
val contact: Contact?, // optional
val company: Company?, // optional
val educations: List<Education>,
) {
class Builder {
var firstName: String? = null
var middleName: String? = null // optional
var lastName: String? = null
var address: Address? = null
var contact: Contact? = null // optional
var company: Company? = null // optional
var educations: List<Education>? = null
fun setFirstName(firstName: String) {
this.firstName = firstName
}
fun setMiddleName(middleName: String) {
this.middleName = middleName
}
fun setLastName(lastName: String) {
this.lastName = lastName
}
fun setAddress(address: Address) {
this.address = address
}
fun setContact(contact: Contact) {
this.contact = contact
}
fun setCompany(company: Company) {
this.company = company
}
fun setEducations(educations: List<Education>) {
this.educations = educations
}
fun build(): User {
return User(
firstName!!,
middleName,
lastName!!,
address!!,
contact,
company,
educations!!
)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment