Last active
January 24, 2021 14:25
-
-
Save le0nidas/5d5a4d56bb97f3fda9e8cbbe421480b9 to your computer and use it in GitHub Desktop.
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
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