Skip to content

Instantly share code, notes, and snippets.

@5AbhishekSaxena
Created June 5, 2023 09:16
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/80f9d1e1a54fa2c3fb0055ec70040d34 to your computer and use it in GitHub Desktop.
Save 5AbhishekSaxena/80f9d1e1a54fa2c3fb0055ec70040d34 to your computer and use it in GitHub Desktop.
class User private constructor(
firstName: String?,
// remaining properties…
) {
val firstName: String
// other properties...
init {
// validations, if any
// set values
this.firstName = firstName
// remaining properties ...
}
class Builder {
private var firstName: String? = null
Other Properties
Public Setters for the builder
// build() that returns the User object.
fun build(): User {...}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment