-
-
Save le0nidas/a57734fc47d8ffbc8176443407e50969 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 PhoneNumberScreen( | |
private val phoneNumber: PhoneNumber | |
) { | |
init { | |
require(phoneNumber.value.isNotEmpty()) { "cannot handle invalid phone number" } | |
} | |
fun render() { | |
println("Phone number: ${phoneNumber.value}") | |
} | |
} | |
fun main() { | |
val contact = Contact(PhoneNumber("12345")) | |
show(contact.phoneNumber) // "Phone number: 12345" | |
val contactWithInvalidPhoneNumber = Contact(PhoneNumber("")) | |
show(contactWithInvalidPhoneNumber.phoneNumber) // prints nothing | |
} | |
private fun show(phoneNumber: PhoneNumber) { | |
try { | |
val phoneNumberScreen = PhoneNumberScreen(phoneNumber) | |
phoneNumberScreen.render() | |
} catch (ex: IllegalArgumentException) { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment