知识卡片
仓库装箱规则先作验证再约束求解
原书假设化学品仓库案例:危险品要求装甲或通风等 Container Feature,Chemical 对应的 Container Specification 能检验容器是否满足要求。先定义 isSafelyPacked 和 Packer 服务的完成条件,再把最优装箱算法藏在服务实现里;无完整解应抛异常。图9.16中的货物、桶、容器及约束是教学模型,既有容器可能已放部分货物,不能仅按特性忽略容量与混装限制。参见[[生成器接口以规格描述结果]]。
结构图:
classDiagram
class Chemical
class ContainerSpecification
class Container
class ContainerFeature
class Drum
Container "1" --> "*" Drum : 装入
Drum "1" --> "1" Chemical : 包含
Chemical "1" --> "1" ContainerSpecification : 约束
ContainerSpecification "1" --> "0..1" ContainerFeature : 要求特性
Container "1" --> "*" ContainerFeature : 提供特性
ContainerSpecification ..> Container : 检验容器
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 原书第09章|How to Model Less Obvious Kinds of Concepts · 查看原书依据
Now the task of designing an optimized constraint solver to fulfill the responsibilities of the Packer service has been decoupled from the rest of the application, and those mechanisms will not clutter the part of the design that expresses the model. (See "Declarative Style of Design," Chapter 10, and COHESIVE MECHANISM, Chapter 15.) Yet the rules governing packing have not been pulled out of the domain objects.
参考来源
- 位置:《Domain-Driven Design: Tackling Complexity in the Heart of Software》第70章《How to Model Less Obvious Kinds of Concepts》,Example Chemical Warehouse Packer,图9.16(源文件:_epub-src/0321125215_ch09lev1sec2_split_000.html)
- 结论依据:原文指出装箱求解机制与服务契约分离,而约束仍留在领域对象。
- 原始内容:Some are volatile and have to be stored in specially ventilated containers. Some are explosive and have to be stored in specially armored containers. There are also rules about the combinations allowed in a container. [...] A method on a Container object, isSafelyPacked(), will confirm that Container has all the features specified by the Chemicals it contains: [...] What we have is a test for a packer. This understanding of the domain and our SPECIFICATION -based model put us in a position to define a clear and simple interface for a SERVICE that will take collections of Drums and Containers and pack them in compliance with the rules. [...] If no complete solution can be found, an exception shall be thrown. [...] Now the task of designing an optimized constraint solver to fulfill the responsibilities of the Packer service has been decoupled from the rest of the application, and those mechanisms will not clutter the part of the design that expresses the model. (See "Declarative Style of Design," Chapter 10 , and COHESIVE MECHANISM , Chapter 15 .) Yet the rules governing packing have not been pulled out of the domain objects.
- 图与代码证据:图9.16有 `Container→Drum→Chemical→Container Specification` 与 `Container Feature` 关系,图中还列出 `Container.capacity`、`Drum.size`;`WarehousePacker` 接口 ASSERTION 注释规定无完整解时抛异常。后续教学原型的 `Container.hasSpaceFor()`/`canAccommodate()` 检查容量与规格,装箱判断不能只看特性。
- 摘录说明:`If no complete solution...` 出自原书 `WarehousePacker` 接口代码中的 ASSERTION 注释;其余片段为相邻正文,非连续处以 `[...]` 标出。