2 Sep 2007 08:58
Re: How to refactor argument validity checking?
Avi Naparstek <avi_a <at> mapa.co.il>
2007-09-02 06:58:20 GMT
2007-09-02 06:58:20 GMT
Hi.
In general, I believe returning results via exceptions creates some
runtime overhead (at least in .Net it does - I'm not sure about Java).
So I'd have checkIBANConstraints() return some other form of result-
code or result-structure instead of throwing exceptions. Something
like this:
private IBANValidationResult result = new IBANValidationResult;
void checkIBANConstraints(String iban)
{
if(!hasValidFormat(iban))
result.IsFormatValid = false;
if(!hasValidChecksum(iban))
result.IsChecksumValid = false;
if(!thirdCondition(iban))
result.IsThirdConditionValid = false;
}
boolean isValidIBAN()
{
if (!result.IsFormatValid) return false;
if (!result.IsChecksumValid) return false;
if (!result.IsThirdConditionValid) return false;
return true;
}
After that I might be tempted to push all the validation code into
(Continue reading)
RSS Feed