Any idea for abstraction CaptchaType? I do it this...
# announcements
x
Any idea for abstraction CaptchaType? I do it this way because the annotation parameter only receive const value( compile-time constant )
m
Are you asking for an advice on how to model a common type for PhoneCaptchaType and ImgCaptchaType?
x
Yeah, or other elegant ways
image.png
image.png
🙄 1
m
depending on what you want to achieve, you could get away with this for example:
Copy code
abstract class CaptchaType {
    open val allowableValues = ""
    val allowableValueList: List<String>
        get() = allowableValues.split(",")
}

object PhoneCaptchaType : CaptchaType() {
    const val MERCHANT_LOGIN = "PHONE_CAPTCHA_MERCHANT_LOGIN"
    const val ADMIN_FORGET_PASS = "PHONE_CAPTCHA_ADMIN_FORGET_PASS"
    override val allowableValues = "$MERCHANT_LOGIN,$ADMIN_FORGET_PASS"
}
so your objects will have initialization logic factored in common. Is that what you wanted?
x
no, allowableValuees isn't compile constant and can't used as annotation parameter
m
okay got it, can’t think of an alternative right now sorry
x
I also think so, thanks
m
Maybe you could drop the List property and just use
ImgCaptchaType.allowableValues.contains(scope)
in the controller
that way your objects will have all compile constants
x
yeah, got it
👍 1
No, there is a big bug, any letter will pass
m
you mean that
contains(scope)
will pass for any string value?
x
yeah, I change it back