July 2018
Intermediate to advanced
242 pages
8h 6m
English
Now, let's give it a try and take a look at how we can use the EmailValidator interface in action. Let's assume we have a RegistrationForm class containing a hook method that is invoked every time the input text is modified:
class RegistrationForm() { fun onInputTextUpdated(text: String) { // do some actions on text changed }}
To make use of our EmailValidator interface, we need to declare a class that is implementing it. We can modify the RegistrationForm class to implement the EmailValidator interface:
class RegistrationForm(override var input: String = ""): EmailValidator { fun onInputTextUpdated(newText: String) { this.input = newText if (!isEmailValid()) { print("Wait! You've entered wrong email...") } else { print(
Read now
Unlock full access