package com.alexfu.formvalidator.rules;


import com.alexfu.formvalidator.utils.Patterns;

public class EmailRule implements ValidationRule {
  private final String errorMessage;

  public EmailRule(String errorMessage) {
    this.errorMessage = errorMessage;
  }

  @Override
  public String errorMessage() {
    return errorMessage;
  }

  @Override
  public boolean isValid(String input) {
    return Patterns.EMAIL_ADDRESS.matcher(input).matches();
  }
}

package com.alexfu.formvalidator.rules;


import com.alexfu.formvalidator.utils.Patterns;

public class EmailRule extends RegexRule {
  public EmailRule(String errorMessage) {
    super(Patterns.EMAIL_ADDRESS, errorMessage);
  }
}

Refactor EmailRule to inherit RegexRule