Skip to content

Instantly share code, notes, and snippets.

@le0nidas
Last active January 24, 2021 14:25
Show Gist options
  • Save le0nidas/5d5a4d56bb97f3fda9e8cbbe421480b9 to your computer and use it in GitHub Desktop.
Save le0nidas/5d5a4d56bb97f3fda9e8cbbe421480b9 to your computer and use it in GitHub Desktop.
class User(
val name: Name,
val age: Age
)
class Name private constructor(
val value: String
) {
companion object {
fun of(value: String): Name {
require(value.length in (2..25))
return Name(value)
}
}
}
class Age private constructor(
val value: Int
) {
companion object {
fun of(value: Int): Age {
require(value in (0..110))
return Age(value)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment