The most complex thing here is how to design validators.
I see three ways:
- (Not convenient for me, but still the way) design it with notations and annotations:
// object here is notation, we assuming that user will
// create object here, but not class. Anyway this will
// be checked at compile time
object NameValidator : Validator<String> {
override fun validate(value: String): Boolean = ...
}
@Validate(NameValidator::class)
val name: String = ""
- (Not convenient for me, but still the way) design it with function name notations:
var name: String = ...
fun _checkName_(): Boolean = ...
Transformed to →
private var _name: String
var name: String get() = _name set() = if(/* code from _checkName_() */) ... else ...
- (Now I'm looking forward this) Wrap it with a type:
val name: Validate<String> = Validate(default = ...) { name -> require(name.length in 1..30) { "Provide a correct name" } }
Transformed to →
var _name: String = default
var name get() = _name set() = if(/* code from name.validate() */) ... else ...
Originally posted by @y9san9 in #1 (comment)
The most complex thing here is how to design validators.
I see three ways:
Originally posted by @y9san9 in #1 (comment)