Re.Mark

My Life As A Blog

Action Man

leave a comment »

Roy Osherove has posted about a validation framework called Validation Everywhere.  It has a lot in common with nspectre (for instance, both make it easy to unit test your validation logic) – the approach is a little different and Validation Everywhere doesn’t seem to have actions (yet.)  Actions are a key concept in nspectre.  They allow you to group specifications.  In practice this is likely to mean things like Add or Delete.  Because actions can inherit from other actions, specifications that are common to a number of specifications can be grouped together and don’t have to be repeated.
I have been asked before why nspectre doesn’t use attributes.  The answer is linked to actions.  A property on a class may need to be a certain length.  It is likely that this need is context sensitive – i.e. we don’t need to check if the property is of the correct length if the object in question is being deleted.  Moving the knowledge of the context outside the class makes it easier to maintain.  It also creates possibilities that would otherwise be very difficult.  For instance, I have spoken to one developer who maintains a site where the validation rules are user specific (e.g. when each user registers and is set up, they can choose how long fields should be and which are mandatory.)  This requirement could be supported in nspectre by having a configuration per user (and one ValidatorFactory per user.)  I guess it’s also worth noting that Context can be used to pass runtime information to specifications.  Context could conceivably be used to the same end – the better approach would be determined by how different the logic was between users.

About these ads

Written by remark

December 17, 2006 at 7:58 pm

Posted in nspectre

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: