Wednesday, February 6, 2008

Fluent Problem Solving by Elimination

Many problems lend themselves to a solution through a process of elimination. These include the selection of scientific hypothesis, technical troubleshooting, medical diagnosis, etc. I have written a small framework to help solve this class of problems. Additionally, I made a fluent interface to create constraint rules. You can download it from the code samples section.

I am planning on creating a few examples in the near future to show it off, but for this post I just want to give a sneak peek at a couple of lines of Java code that uses it. This comes from a test that categorizes an animal based on observable qualities. This is the definition of one constraint rule that allows the system to know that no mammals have scales or feathers.

constraint = when(skin).is(scaley).or(skin).is(feathery).then(animalType).isNot(mammal);

Here is another that tells the system that only bats have both fur and wings:

constraint = when(skin).is(furry).and(phalanx).is(wings).then(animal).is(bat);