You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So we have validation result as boolean and also the concept to throw an exception if the validation fails in a properties validator.
Both approaches are not well designed.
Instead we should create an interface ValidationResult
public interface ValidationResult {
boolean isValid();
String getErrorMessage();
}
Then we can create an implementation ValidationState:
public class ValidationState implements ValidationResult {
private final StringBuilder errorMessage;
public boolean isValid() {
return (this.errorMessage == null);
}
public String getErrorMessage() {
if (this.errorMessage == null) {
return null;
}
return this.errorMessage.toString();
}
public void addErrorMessage(String error) {
if (this.errorMessage == null) {
this.errorMessage = new StringBuilder(error.length());
} else {
this.errorMessage.append('\n');
}
this.errorMessage.append(error);
}
}
This is just a design suggestion as starting point. We can also have a immutable implementation(s) of ValidationResult and have a ValidationResult toResult() method in ValidationState.
The final idea is that internal validation methods will take a ValidationState object as argument. This also applies for the validators of the Property classes. Here we need to change from Consumer<V> to a custom interface:
The main API should take no argument and return ValidationResult.
An alternative approach is to skip the ValidationState and always return ValidationState and then add some aggregation logic that can compose multiple ValidationState objects into one. IMHO the latter approach is slightly more complex.
The text was updated successfully, but these errors were encountered:
Currently our validation is not implemented well:
IDEasy/cli/src/main/java/com/devonfw/tools/ide/commandlet/Commandlet.java
Lines 202 to 216 in eae8fd2
IDEasy/cli/src/main/java/com/devonfw/tools/ide/property/Property.java
Lines 456 to 467 in eae8fd2
So we have validation result as
boolean
and also the concept to throw an exception if the validation fails in a properties validator.Both approaches are not well designed.
Instead we should create an interface
ValidationResult
Then we can create an implementation
ValidationState
:This is just a design suggestion as starting point. We can also have a immutable implementation(s) of
ValidationResult
and have aValidationResult toResult()
method inValidationState
.The final idea is that internal validation methods will take a
ValidationState
object as argument. This also applies for the validators of theProperty
classes. Here we need to change fromConsumer<V>
to a custom interface:The main API should take no argument and return
ValidationResult
.An alternative approach is to skip the
ValidationState
and always returnValidationState
and then add some aggregation logic that can compose multipleValidationState
objects into one. IMHO the latter approach is slightly more complex.The text was updated successfully, but these errors were encountered: