Last active
May 15, 2020 04:38
-
-
Save amatkivskiy/1f97c144fb876c39aab6ca368a1c9684 to your computer and use it in GitHub Desktop.
For medium article: https://medium.com/@amatkivskiy/legacy-code-pitfalls-35feda5acb71
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
data class Parent(val child: Nested?) | |
class Nested(val child: Nested?, val isValid: Boolean = false) | |
// Assume you got this object from the dark and deep internals of your app | |
val parentObj = getParentObjFromInternals() | |
doSomethingOnBooleanValue(parentObj.child?.child?.child?.isValid) | |
fun doSomethingOnBooleanValue(valid: Boolean?) { | |
if (valid == true) { | |
// `valid` is really true | |
} else { | |
// `valid` is false or null | |
} | |
} | |
fun getParentObjFromInternals() = Parent(Nested(Nested(Nested(null, true)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment