Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / May 2008

Tip: Looking for answers? Try searching our database.

DataValidator class?

Thread view: 
thufir - 15 May 2008 11:13 GMT
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.

What's the standard approach?  Multiple anonymous inner classes?   A
static utility class?  Verify the data before sending it to the
constructor?

Or, create a DataValidator class which the constructor instatiates?

thanks,

Thufir
Andrea Francia - 17 May 2008 12:40 GMT
> 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

Signature

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



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.