Re: Improving ugly(?) design: Data validation
Rune Allnor <allnor@tele.ntnu.no> writes:
I have this class to validate a string according to a
specification contained in a string.
A class models an entity, a function models an activity.
To validate is an activity. So, this responsibilit can
be assigned to a function, not a class.
Exceptions are intended to signal that a function can
not perform its job. When the job is to map strings
to a report, a report reporting an erroneous string is
not an indication for an exception. In other words:
?Nothing's an emergency in an emergency room because you expect it.?
http://www.boston.com/news/science/articles/2008/05/26/the_go_to_guy_in_mental_health_studies/?page=full
So one might write a method such as
report status( ::std::string const & string )
{ ... }
and an appropriate
class report { ... }
The usage might be, for example,
report const string_status( status( string ));
if( string_status.is_good() )... else ::std::cerr << string_status;
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]