返回主题:领域逻辑的组织方式

知识卡片

普通读书笔记卡 · 1971.o.1.b.4.d.1.a

层间设计依赖保持单向

理解等级:中级

分层架构中的设计依赖应指向同层或下层。上层可调用下层公开接口;下层若要主动通知上层,可借助回调或观察者等间接机制,避免直接了解上层的具体对象。基础设施通常提供可调用的技术服务,例如发送消息:应用层决定何时发送,基础设施负责如何发送。这样既连接各层,也保留[[四层架构按职责隔离]]的边界。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    参考来源

    - 位置:《Domain-Driven Design: Tackling Complexity in the Heart of Software》第30章《原书第04章|Layered Architecture》(源文件:_epub-src/0321125215_ch04lev1sec1.html;图04inf02.gif) - 结论依据:原文明确规定层内或向下依赖,上行通信使用间接机制,并用消息发送服务解释应用层与基础设施层的职责分界。 - 原始内容:The essential principle is that any element of a layer depends only on other elements in the same layer or on elements of the layers "beneath" it. Communication upward must pass through some indirect mechanism, which I'll discuss a little later. [...] Layers are meant to be loosely coupled, with design dependencies in only one direction. Upper layers can use or manipulate elements of lower ones straightforwardly by calling their public interfaces, holding references to them (at least temporarily), and generally using conventional means of interaction. But when an object of a lower level needs to communicate upward (beyond answering a direct query), we need another mechanism, drawing on architectural patterns for relating layers such as callbacks or OBSERVERS ( Gamma et al. 1995 ). [...] For example, if an application needs to send an e-mail, some message-sending interface can be located in the infrastructure layer and the application layer elements can request the transmission of the message. [...] But the main benefit is simplifying the application layer, keeping it narrowly focused on its job: knowing when to send a message, but not burdened with how . (`[...]` 标明非连续省略;末尾句号前空格是原 EPUB 标签抽取形式。)