Prev | Current Page 341 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

value = value;
this.pattern = pattern;
this.opt = if(opt == null) ?????? else opt;
}
public function validate() : Bool
{
var er = new EReg(pattern, opt);
if(er.match(value))
return true;
else {
error = ?????™???+value+?????™ does not match the expression /???+pattern+???/???;
return false;
}
}
}
The framework can be extended and completed adding new validation classes for numeric ranges, credit
card numbers, phone numbers, and so on. A common interface Validator can be introduced to make
the classes exchangeable and maybe changing the error variable type from String to List < String >
could be a good idea. This way a single Validator could notify more than one reason of failure. A
generic ValidatorGroup class could be introduced to perform many chained validations at once.
Summary
In this chapter you learned a lot about structuring the code so that it will make your work easier. A lot
was covered and you now can master the following arguments:
Packages
Using and producing external libraries
Documenting the code using the XML files generated by the compiler and the comments in the code
Unit Testing and how to write them
In the next chapter, you learn how to deal with error handling and debugging in general.


Pages:
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353