知识卡片
制造异常可由操作层事件传给政策层
原书制造示例:政策层规定正确加工流程,操作层记录工厂实际状态;即使零件被放错设备,操作层也不能因为违反政策而拒绝事实。决策层可依据其他政策决定返修或报废。若直接让操作层调用高层,会形成逆向依赖。
可让操作对象在状态变化时发出事件,由政策对象订阅并在规则被触发时执行动作,或继续向更高层发事件。这里的事件机制是原书提出的典型通信方式,具体系统仍需按技术环境选择。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 原书第16章|How Restrictive Should a Structure Be? · 查看原书依据
When an event occurred that violated a rule, the rule would execute an action (part of the rule's definition) that makes the appropriate response, or it might generate an event for the benefit of some still higher layer.
参考来源
- 位置:《Domain-Driven Design: Tackling Complexity in the Heart of Software》第133章《How Restrictive Should a Structure Be?》(源文件:_epub-src/0321125215_ch16lev1sec6.html;单元01)
- 结论依据:原文制造示例先区分事实与政策决策,再描述由低层发事件、高层监听和处置的通信方式。
- 原始内容:The correct process is ordered from a Policy layer and executed in an Operations layer. But inevitably there will be mistakes made on the factory floor. The actual situation will not be consistent with the rules of the software. Now, an Operations layer must reflect the world as it is, which means that when a part is occasionally put in the wrong machine, that information must be accepted unconditionally. Somehow, this exceptional condition needs to be communicated to a higher layer. A decision-making layer can then use other policies to correct the situation, perhaps by rerouting the part to a repair process or by scrapping it. But Operations does not know anything about higher layers. The communication has to be done in a way that doesn't create two-way dependencies from the lower layers to the higher ones. [...] The Operations objects would generate events whenever their state changed. Policy layer objects would listen for events of interest from the lower layers. When an event occurred that violated a rule, the rule would execute an action (part of the rule's definition) that makes the appropriate response, or it might generate an event for the benefit of some still higher layer.
- 转录说明:`[...]` 标明两段非连续摘录的省略;原卡术语与逗号之间的多余空格来自 EPUB 标签边界,已规范转录。