知识卡片

结构图卡 · 1971.o.1.c.1.a.1.c.3.b

规格逻辑组合保持同类结果

理解等级:中级

规格(Specification)可被看作判断候选对象是否满足条件的谓词。对两个规格做 and、or,或对一个规格做 not,返回的仍是规格;这些操作因此在规格类型下构成运算闭包。

原书的化学品装箱教学例子:ventilated.and(armored) 表示两项都要满足;两个通风容器规格用 or 表示任一可用;ventilated.not().and(armored.not()) 可表达无需专用条件的“廉价容器”。图10.14把叶规格及 AND/OR/NOT 组合件挂在同一规格接口下。此处是规则表达示意,不代表任何装箱算法已验证。

结构图:

classDiagram
    class Specification {
      +isSatisfiedBy(candidate) bool
      +and(other) Specification
      +or(other) Specification
      +not() Specification
    }
    class LeafSpecification
    class AndSpecification
    class OrSpecification
    class NotSpecification
    Specification <|.. LeafSpecification
    Specification <|.. AndSpecification
    Specification <|.. OrSpecification
    Specification <|.. NotSpecification
    AndSpecification --> Specification : 组合两个
    OrSpecification --> Specification : 组合两个
    NotSpecification --> Specification : 包裹一个
这张卡片看不懂?

已有反馈 · 0 / 10 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • 原书第10章|A Declarative Style of Design · 查看原书依据

      When using SPECIFICATIONS, you quickly come across situations in which you would like to combine them. As just mentioned, a SPECIFICATION is an example of a predicate, and predicates can be combined and modified with the operations "AND," "OR," and "NOT." These logical operations are closed under predicates, so SPECIFICATION combinations will exhibit CLOSURE OF OPERATIONS.

    参考来源

    - 位置:《Domain-Driven Design: Tackling Complexity in the Heart of Software》第81章《A Declarative Style of Design》(源文件:_epub-src/0321125215_ch10lev1sec8.html;单元01) - 结论依据:原文把规格视为谓词,以 AND/OR/NOT 构造仍为规格的组合;图10.14显示统一接口下的叶规格和复合规格。 - 原始内容:When using SPECIFICATIONS , you quickly come across situations in which you would like to combine them. As just mentioned, a SPECIFICATION is an example of a predicate, and predicates can be combined and modified with the operations "AND," "OR," and "NOT." These logical operations are closed under predicates, so SPECIFICATION combinations will exhibit CLOSURE OF OPERATIONS .