实现 NotSpecification: isSpecialCaseOf 的好方法?
我正在实施规范模式。 NotSpecification 乍一看似乎很简单:
NotSpecification.IsSpecialCaseOf(otherSpecification)
return !this.specification.isSpecialCaseOf(otherSpecification)
但它并不适用于所有规范:
Not(LesserThan(4)).IsSpecialCaseOf(Equals(5))
这应该返回 false 而不是 true。到目前为止,我认为完成 isSpecialCaseOf NotSpecification 的唯一方法是实现remainingUnsatisfiedBy(论文中关于规范模式的部分包含)。但也许我错过了一些更简单的东西或逻辑洞察力,使得这变得不必要。
问题:是否有另一种不使用remainingUnsatisfiedBy 的方法来实现这一点?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我尝试在 Java 中实现这一点,它没有出现任何问题,也没有剩余的 UnsatisfiedBy()。可能您在实现中遇到了一些问题,这是我的:
问题在于 Not() 方法,该方法应该正确构造其参数的相反类型。
那么我需要的就是为每个规范正确实现 not() ,例如对于 LesserThan:
如果您有任何问题,请提供您的 GreatherThan.isSpecialCaseOf 和 Not 的实现,我会尽力提供帮助。
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.