知识卡片

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

路线权重策略显化选择标准

理解等级:高级

原书的货运路线教学例子中,Routing Service 接受 Route Specification,构造满足约束的 Itinerary。若把“最快/最便宜”做成两个服务入口,选择条件会散落在计算过程。改为传入 Leg Magnitude Policy:它把每段路程的时间或成本转成数值,服务按选定策略寻找总权重最小的路线。

这样“按什么评价路线”成为可讨论、可测试的领域规则。图12.2中的时间与金额策略是同一政策接口的可选实现,每次查找传入其中一种;该例没有证明实际求解性能,不能把概念清晰等同于算法高效。

结构图:

classDiagram
    class RoutingService {
      +find(specification, policy) Itinerary
    }
    class LegMagnitudePolicy {
      +length(leg) double
    }
    class LegTimeMagnitude
    class LegMoneyMagnitude
    LegMagnitudePolicy <|-- LegTimeMagnitude
    LegMagnitudePolicy <|-- LegMoneyMagnitude
    RoutingService ..> LegMagnitudePolicy : 每次传入一种实现
这张卡片看不懂?

已有反馈 · 0 / 10 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • 原书第12章|Strategy (A.K.A.Policy) · 查看原书依据

      A fundamentally important rule in the domain, the basis of choosing one Leg over another when building an Itinerary, is now explicit and distinct. It conveys the knowledge that a specific attribute (potentially derived) of an individual leg, boiled down to a single number, is the basis for routing.

    参考来源

    - 位置:《Domain-Driven Design: Tackling Complexity in the Heart of Software》第88章《Strategy (A.K.A.Policy)》(源文件:_epub-src/0321125215_ch12lev1sec1.html;单元01) - 结论依据:原文与图12.1–12.2对比服务接口选项和传入Leg Magnitude Policy;服务行为被定义为总权重最小,作者另提醒直接枚举Leg的原型可能低效。 - 原始内容:A fundamentally important rule in the domain, the basis of choosing one Leg over another when building an Itinerary , is now explicit and distinct. It conveys the knowledge that a specific attribute (potentially derived) of an individual leg, boiled down to a single number, is the basis for routing.