public abstract class AbsXXXValidator {
protected AbsXXXValidator nextValidator;
public void setNextValidator(AbsXXXValidator absValidator) {
this.nextValidator = absValidator;
}
public abstract Result isValidatePass();
public Result nextValidator() {
if (nextValidator == null) {
return succeedResult();
}
return nextValidator.isValidatePass();
}
}
public class XXXValidatorChainBuilder {
private AbsXXXValidator firstValidator;
private AbsXXXValidator lastValidator;
public XXXValidatorChainBuilder setValidator(AbsXXXValidator absValidator) {
if (firstValidator == null) {
firstValidator = absValidator;
lastValidator = absValidator;
return this;
}
lastValidator.setNextValidator(absValidator);
lastValidator = absValidator;
return this;
}
public AbsXXXValidator build() {
return firstValidator;
}
}