Consider a standard ASP.NET web application where the user types in some numeric data on a form. On submitting, some business objects are spun up to operate on the numeric data. But server-side textbox controls in .Net return a value of type string. Question: Should the codebehind of the page take responsibility for parsing the strings into numeric data (and throwing errors if invalid), or should the business objects accept strings for their input and parse them themselves?
Consider a standard ASP.NET web application where the user types in some numeric data
Share
IMO, the business objects should accept numeric types only. Strings can be parsed in various formats, according to culture specific rules. Numbers are numbers. You don’t want to change your business objects for localization – accepting only numbers will make it easier to reuse.