String versus Decimal. Strong datatyped properties of a business class - TechRepublic
General discussion
November 23, 2004 at 03:02 PM
urri oz

String versus Decimal. Strong datatyped properties of a business class

by urri oz . Updated 21 years, 7 months ago

Let’s say we need to collect details on a car and its value in particular. Therefore we have a UI element txtCarValue (Textbox), a business object -class Vehicle with a property Vehicle.CarValue and table Vehicle with column CarValue DECIMAL (would need to do some calculation with it later). To avoid meaningless data there is also a business rule validation: CarValue has to be greater than $0.00. Therefore there are two validations on CarValue property. Since UI element is a textbox (free typing) we need to validate that 1) typed in data is NUMERIC and 2) it is > 0. There are two options to handle it:
1)Define the property Vehicle.CarValue as datatype STRING and have both validations while Setting the property. Firstly, validate ISNUMERIC. If fails, raise an error “Wrong Format”. Then, assuming it is NUMERIC, validate Vehicle.CarValue > 0, if fails, raise an error “Wrong Value”. When the value is valid use CDec(CarValue) to save to the table.
2) Define the property Vehicle.CarValue as DECIMAL, validate when setting the property if Vehicle.CarValue >0. If fails, raise an error “Wrong Value”. This option also requires validation on UI level to make sure that typed in data is NUMERIC.
I would appreciate other people opinions on these options. Personally I favour 1st one (STRING) as in this case a business class is self-sufficient, all validations in one place, the class can be easily re-used in UI-less data exchange. But I may not see possible obstacles.
Cheers,

This discussion is locked

All Comments