May 21st, 2015

If you can set enforcement for a rule, you can set up lack of enforcement

One of the things you can do with an internal tool I’ve been calling Program Q is run a program any time somebody wants to add or modify a record. The program has wide latitude in what it can do. It can inspect the record being added/modified, maybe record side information in another table, and one of the things it can decide to do is to reject the operation.

We have set up a validator in our main table to ensure that the widget being added or modified is priced within the approver’s limit. But sometimes, there is an urgent widget request and we want to be able to bypass the validation temporarily. Is there a way to disable the validator just for a specific record, or to disable it for all records temporarily?

If you can set up a program to validate a record, you can also set up a program to not validate a record.

Suppose your current validator for adding a widget goes like this:

if (record.approver.limit < record.price) {
 record.Reject("Price exceeds approver's limit");
 return;
}
... other tests go here ...

And say you want to be able to allow emergency requests to go through even though, say, all approvers are unavailable. Because, maybe, the widget is on fire.

You could decide that a widget whose description begins with the word EMERGENCY is exempt from all validation, but it generates email to a special mailing list.

if (record.description.beginsWith("EMERGENCY"))
{
 // emergency override: send email
 // and bypass the rest of validation
 generateNotificationEmail(record);
 return;
}
if (record.approver.limit < record.price) {
 record.Reject("Price exceeds approver's limit");
 return;
}
... other tests go here ...

Of course, the EMERGENCY rule was completely arbitrary. You can come up with whatever rules you like. The point is: If you wrote the rules, you can also write the rules so that they have exceptions.

Topics
Other

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.