如何使用复合规范模式实现 isGeneralizationOf ?
我正在尝试按照 Fowler 和 Evans 的 规范文档 来实现复合规范模式。
乍一看,我认为 isGeneralizationOf
的实现对于合取和析取会有所不同。
特别是,我认为合取的逻辑是
(1) 令specX 为specA 和specB 的合取。那么,只有当specA和specB都是specC的泛化时,specX才是specC的泛化。
并且我认为析取的逻辑将是
(2)令specY为specA和specB的析取。那么,如果specA或specB是specC的泛化,则specY是specC的泛化。
但是,在文档的第16页上,他们展示了这个方法:
CompositeSpecification >> isGeneralizationOf: aSpecification
"True if each component is subsumed. False if any component is not subsumed."
^ (self components contains:
[:each |(each isGeneralizationOf: aSpecification) not ]) not
我在(1)和(2)中的推理正确吗?如果是错的,那是为什么呢?如果它是正确的,那么为什么作者定义一个由合取和析取规范继承的单一方法?他们来这里的目的是什么?
I am trying to implement the composite specification pattern, as per the Specifications Document by Fowler and Evans.
At first impression, I thought the implementation of isGeneralizationOf
would be different for conjunction and disjunction.
In particular, I thought the logic for conjunction would be
(1) Let specX be the conjunction of specA and specB. Then, specX is a generalization of specC only if both specA and specB are a generalization of specC.
And I thought the logic for disjunction would be
(2) Let specY be the disjunction of specA and specB. Then, specY is a generalization of specC if either specA or specB is a generalization of specC.
However, on page 16 of the document , they show this method:
CompositeSpecification >> isGeneralizationOf: aSpecification
"True if each component is subsumed. False if any component is not subsumed."
^ (self components contains:
[:each |(each isGeneralizationOf: aSpecification) not ]) not
Is my reasoning in (1) and (2) correct? If it's wrong, why is that? If it's correct, then why did the authors define a single method to be inherited by both conjunction and disjunction specifications? What is their intent here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
示例:
如果您首先定义对象 a 和 b,则可以在 Squeak 中获得如此好的语法,因为 {} 是动态数组文字的特殊语法(在 Array 类中定义 isSpecializationOf:)。
Examples:
You can get the syntax this nice in Squeak if you first define the objects a and b, since {} is a special syntax for dynamic array literals (define isSpecializationOf: in class Array).
#includesAllOf:在类 Collection 中定义
#includesAllOf: is defined in the class Collection