He
12/13/2022, 2:12 AMclass someClass(){
lateinit var one: String,
lateinit var two: String,
lateinit var three: customObject
}
So what I'm doing is throughout my code I'm updating these variables based on some conditions/criteria and I have another class that calls someClass
and I will use getters to retrieve the lateinit var
. Instead of these singleton variables, what should I be using? Should I be using a custom data class
to store the state of the variables?
The logic I have for these variables:
one - Does the data already exist? yes -> one = existingData.one no -> one = generate some value and set
two - Does the data already exist? yes -> two = existingData.two no -> two = generate some value and set && Are we done? yes -> no nothing. no -> generate some value and set
three - Just update consistently to get the most recent Object to be passed into different classAndrew O'Hara
12/13/2022, 3:12 AMlazy
delegated properties. These properties will evaluate the lazy
block the first time they're accessed, and cache the result for future accesses.
class SomeClass {
val one by lazy {
"foo" + "bar" + "baz"
}
}
Rather than have other modules mutate the properties of SomeClass
, you might inject whatever dependencies you need into SomeClass
so it can compute the values itself.
https://kotlinlang.org/docs/delegated-properties.htmlHe
12/13/2022, 4:36 AMStephan Schröder
12/13/2022, 8:42 AM