Visibility
The visibility access rules we have discussed for fields apply to properties as well. Therefore, you can have private, protected, or public (default) properties. Furthermore, the setter can have different, more restrictive visibility than the getter (the getter code is generated for you automatically in the following case):
class WithPrivateSetter(property: Int) { var SomeProperty: Int = 0 private set(value) { field = value } init { SomeProperty = property } } val withPrivateSetter = WithPrivateSetter(10) println("withPrivateSetter:${withPrivateSetter.SomeProperty}")
There are scenarios when properties are subject to class inheritance. If this happens, typically protected visibility, at least for the setter, is more appropriate:
open class WithInheritance { open var isAvailable: Boolean = false get() =...