I’m implementing the specification pattern. The NotSpecification seems simple at first:
NotSpecification.IsSpecialCaseOf(otherSpecification)
return !this.specification.isSpecialCaseOf(otherSpecification)
But it doesn’t work for all Specifications:
Not(LesserThan(4)).IsSpecialCaseOf(Equals(5))
This should return false instead of true. So far I think that the only way to accomplish the isSpecialCaseOf the NotSpecification is to implement the remainderUnsatisfiedBy (partial subsumption in the paper on the specification pattern). But maybe I am missing something more simple or a logical insight that makes this unnecessary.
Question: Is there another way of implementing this by not using remainderUnsatisfiedBy?
I have tried to implement this in Java and it went without problems and remainderUnsatisfiedBy(). Probably you have some problem in your implementation, here is mine:
The catch is in the Not() method, which should correctly construct opposite type of its argument.
Then all I need is to have correct implementation of not() for every Specification, e.g. for LesserThan:
If you have any problems, please provide your implementation of GreatherThan.isSpecialCaseOf and of Not, I will try to help.