tags:

views:

40

answers:

1

By raw values, I mean the application level values provided by UI controls, such as the Text property on a TextBox. Too often I find myself writing code to check and parse such values before they get used as a business level value, e.g. PaymentTermsNumDays.

I've mitigated a lot of the spade work with rough and ready extension methods like String.ToNullableInt, but we all know that just isn't right. We can't put the whole world on String's shoulders.

Do I look at tasking my UI to provide business values, using a ruleset pushed out from the server app, or open my business objects up a bit to do the required sanitising etc. as they required? Neither of these approaches sits quite right with me; the first seems closer to ideal, but quite a bit of work, while the latter doesn't show much respect to the business objects' single responsibility. The responsibilities of the UI are a closer match.

Between these extremes, I could also just implement another DTO layer, an IoC container with sanitising and parsing services, derive enhanced UI controls, or stick to copy and paste inline drudgery.

A: 

You want an API like Spring's DataValidation. It provides a nice way to validate and bind values that's written in such a way that it's even useful outside of UI.

In my mind, useful outside the UI IS orthogonal. The Spring binding API is routinely used in its web MVC implementation, but it knows nothing about controls. Even if you don't use it, I'd recommend reading about the Spring design. There's much worth emulating there.

I've only used the Java version, but there's a Spring.NET that's supposed to be quite capable.

duffymo
@duffymo, I might look at that, but I'm ultimately seeking to make the validation/cleaning transparent and orthogonal to the relationshion between model and UI. Maybe I need a suite of derived controls that doesn't add functionality, but overrides getters and setters to call into validation services etc.
ProfK
I don't see how derived controls are transparent or orthogonal to UI. And validation services? I hope you don't mean web services.
duffymo