mardi 11 août 2015

Validator class that validates by several simple criterias - is this God-object?

I have java class Validator. It validates some file. Here is it on pseudo code

public class Validator {
    Collection<ValidationMessage> validationMessages;

    class ValidationMessage {
    }

    enum MessageType {
    }

    public validate(lines) throws ValidationException {
        for (line : lines) {
            validateCriteriaA(line)
            validateCriteriaB(line)
            ... 
            validateCriteriaF(line)
        }
        if (...)
            throw new ValidationException();
    }

    private validateCriteriaA(Line line) {
        if (...) {
            validationMessages.add("criteria failed")
        }
    }
    private validateCriteriaB(Line line)
    private validateCriteriaC(Line line)
    private validateCriteriaD(Line line)
    private validateCriteriaE(Line line)
    private validateCriteriaF(Line line)
    private helperMethodX
    private helperMethodY
    private helperMethodZ
}

Each method has no more than 15 lines. Total length of class ~300 lines. Do you think it is God object or some other bad smelling class? Kind of some anti-pattern? If you think it needs to be redesigned - please tell how.

Aucun commentaire:

Enregistrer un commentaire