is it pretty common for people to have there own mutable types for private use in a system, then having a immutable version of the same type for exposing that object publicly?
s
Sam
11/17/2018, 9:06 PM
Android ViewModel uses this pattern
Sam
11/17/2018, 9:06 PM
Copy code
class MainViewModel : ViewModel() {
val valuesLiveData : LiveData<Int>
get() = mutableLiveData
private val mutableLiveData : MutableLiveData<Int> = MutableLiveData()
}
s
Shawn
11/17/2018, 9:10 PM
important note, it’s not an “immutable” version per se - it’s just exposed with a read-only interface
c
Chris Cunningham
11/18/2018, 1:28 AM
yeah i am used to only exposing read - only with the getter, but was looking at something like having my class that is mutated, but when giving the data it contains to other objects simply just create a new data class with values only over