If your validations are the same in multiple class...
# getting-started
u
If your validations are the same in multiple classes you can delegate it to special class:
Copy code
import kotlin.reflect.KProperty
class StringValidator {
    private lateinit var field: String
    operator fun getValue(thisRef: Any?, property: KProperty<*>) = field
    operator fun setValue(thisRef: Any?, property: KProperty<*>, value: String) {
        if(value.isEmpty()) throw IllegalArgumentException("Empty ${property.name}")
        field = value
    }
}
And use in business code:
Copy code
class Person(name: String) {
    var name by StringValidator()
    init {
        this.name = name
    }
}