Last active
July 20, 2016 08:26
-
-
Save minibugdev/068b3df36cf78c390cd4977efdc9f402 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class Validator() { | |
var errorListener: OnErrorListener? = null | |
var validateValue: Any? = null | |
protected abstract fun hasError(): Boolean | |
fun validate(): Boolean { | |
if (hasError()) { | |
errorListener?.onError() | |
return false | |
} | |
return true | |
} | |
interface OnErrorListener { | |
fun onError() | |
} | |
} | |
class Main { | |
val validator = ExtentedValidator() | |
fun testValidator() { | |
validator.errorListener = object : ValidationRule.OnErrorListener { | |
override fun onError() { | |
// show error | |
} | |
} | |
if(validator.validate()) { | |
// Do something ... | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Try to use Lambda instead of listener interface.
and change calling statement to
Now in
Main
class, we can change to