Re: DataValidator class?



thufir wrote:
I have a few related classes which throw a DataException from the constructor if the data passed is invalid. I can't exactly say that the data validation is exactly the same for these classes, but they're similar. Basically, count the number of String[] elements, try to parse Integer or Float values and so forth; there's some overlap.
Where come from these String of the String[] array?

What's the standard approach? Multiple anonymous inner classes? A static utility class? Verify the data before sending it to the constructor?
You are putting the parsing of the Strings in the object constructor.
For better reusability I suggest you to move this responsibility to another class called Parser that read the Strings and returns the parameters to be used for calling the the object constructor. If the parsing fails it throws a ParseException.


Or, create a DataValidator class which the constructor instatiates?



thanks,

Thufir


--
Andrea Francia
http://code.google.com/p/remoted-list/ - Lazy loading lists through RMI.
.



Relevant Pages

  • Re: a method to make js have the ability to inherit
    ... but without the implied type-conversion of the string ... that uses the name of a specific constructor. ... programmer has no idea at all what types of object they are ... no reason for ever doing so. ...
    (comp.lang.javascript)
  • Re: Newbie question: Writing your own class
    ... is made by a class's Create constructor method which allocates memory ... FDefinition: string; ... every other descendant of TObject ... Result:= FDefinition; ...
    (comp.lang.pascal.delphi.misc)
  • Re: About speed
    ... property Name: String read fName; ... constructor TProperty.Create; ... fValue: PropertyOfT_DataType; ... constructor Create(other: TPropertyOfT); overload; ...
    (borland.public.delphi.non-technical)
  • Re: a method to make js have the ability to inherit
    ... discriminating but without the implied type-conversion of the string ... makes no use of an object's - constructor - property anyway.) ... programs should serve some known purpose known to the programmer. ... var o = Father.prototype; ...
    (comp.lang.javascript)
  • Re: regex into str
    ... people confronted with it to reject python as language. ... Don't get me wrong - there is a lot of decisions to be made in language ... The only thing you really need is a simple constructor for your undoubtly ... Overloading "" as the string ...
    (comp.lang.python)