This site will look much better in a browser that supports web standards, but is accessible to any browser or Internet device.
In attempting to do Test Driven Development, we noticed that one of the problems with testing object validation code was the necessity to have broken objects to test with. This is particularly important in cases where the internals of an object may come from somewhere uncontrolled. For instance, objects that may be read from disk could be restored from a damaged file, resulting in objects that should not occur in normal practice.
In many cases, you would just generate an isValid()
type method that could be used to detect the invalid condition and let the user of the object deal with the situation. The question remains, how do you validate the object validation code?
Obviously, you do not want to expose your private data to access from the outside world. You may not even want to expose it to your descendants. You certainly do not want to expose methods publicly that could be used to generate an invalid object. That defeats one of the purposes of having a class.
A Smite class is a derived class that accesses a protected interface and has the ability to damage an object or generate inconsistent state in the object. This class would not be part of the public hierarchy, but it would be available for testing.
You might ask why we called it the Smite class.
One definition of smite is To inflict a heavy blow on... It may also mean to kill.
The particular image I have of the smite is from an old Far Side cartoon that was labelled God at his computer. In the picture, God in the form of a bearded, white-haired old man is looking at a computer screen. On the display, some poor slob is walking down the sidewalk and is about to pass underneath a piano hanging from a rope. "God's" finger is poised over a key labelled smite.
A Smite class is a derived that can inflict heavy damage on the internal data of the object. When this object is used as it's base type, it should be damaged or inconsistent. This allows for testing of validation and/or recovery code.
Posted by GWade at January 14, 2004 08:16 PM. Email comments