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);
2 comments:
Can it solve the Zebra puzzle?
Evidently not :( What a great test though. In the process I found a bug. That Zebra puzzle has a lot of assumptions built in, and I think that the current reason that it isn't working has to do with not fully capturing those assumptions.
I assure you, though, that the fluent api makes it read very nicely. I will try a bit more to get it to work, but if I don't figure it out soon I would probably be better off to wrap some known working constraint engine with a fluent api rather than using mine that was really designed just for a few toy examples.
Post a Comment