September 13, 2004 - Creating a Value Type for Validation (revisited)

Earlier in the year I wrote about introducing a wrapper type to encapsulate the validation of a value that is essentially just a string (see Fight Complexity with Complexity). I just ran into the flip-side of this - the anti-pattern if you like - and I felt compelled to rant about it.

We have a class called ClassName that represents ... wait for it ... a class name. One of the strengths of Agitator is that, if you need a particular type to construct the object under test, it will go and make one for you - and Agitator is extremely good at finding those edge cases that you didn't think of. I recently inherited a bunch of code (and tests) from someone else that used ClassName extensively. He - or rather, Agitator - discovered that his code would break if passed a ClassName that was the empty string. In this situation he had three options :

  1. Change his code to deal with the empty string
  2. Change ClassName to disallow the empty string
  3. Change all his tests to special case the empty string

Unfortunately for me, he went with option 3 as I discovered when someone else just updated ClassName and all his tests (about 50 of them) started failing because they no longer received empty strings.

Posted by Kevin Lawrence at September 13, 2004 10:45 AM

Trackback Pings

TrackBack URL for this entry:


Post a comment

Remember Me?