implier
implier copied to clipboard
Data validation
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:
Transformed to →var name: String = ... fun _checkName_(): Boolean = ...
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:
Transformed to →val name: Validate<String> = Validate(default = ...) { name -> require(name.length in 1..30) { "Provide a correct name" } }
var _name: String = default var name get() = _name set() = if(/* code from name.validate() */) ... else ...
Originally posted by @y9san9 in https://github.com/y9vad9/implier/issues/1#issuecomment-984492558