知识卡片

普通读书笔记卡 · 1971.o.3.a.1.b.1.a.2.a

验证用规格评估单个候选对象

理解等级:中级

验证场景中,调用者构造 DelinquentInvoiceSpecification,并以 isSatisfiedBy(invoice) 判断一张发票是否拖欠;原书示例把评估日期放进规格对象,使判断有明确时间基准。调用者可遍历某客户发票,只要一张满足就提示账户有拖欠。这里的宽限期规则为教学示例,不是现实催收规范。参见[[规格统一验证查询与按需生成]]。

这张卡片看不懂?

已有反馈 · 0 / 10 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    参考来源

    - 位置:《Domain-Driven Design: Tackling Complexity in the Heart of Software》第70章《How to Model Less Obvious Kinds of Concepts》,Validation,图9.14(源文件:_epub-src/0321125215_ch09lev1sec2_split_000.html) - 结论依据:原文用单个对象的真假判断说明验证,并给出拖欠发票示例代码。 - 原始内容:Validation The simplest use of a SPECIFICATION is validation, and it is the use that demonstrates the concept most straightforwardly. [...] Now, suppose we need to display a red flag whenever a salesperson brings up a customer with delinquent bills. We just have to write a method in a client class, something like this. [...] Validation tests an individual object to see if it meets some criteria, presumably so that the client can act on the conclusion. - 示例代码节选:`Specification delinquentSpec = new DelinquentInvoiceSpecification(today);`;`if (delinquentSpec.isSatisfiedBy(candidate)) return true;`。原书先遍历 `customer.getInvoices()`,再对每张候选发票调用规格;`currentDate` 存于规格对象(见同页 `DelinquentInvoiceSpecification(Date currentDate)` 构造器)。 - 摘录说明:原文 `Validation` 是小节标题;正文引文省略了上述示例代码及小节之间的说明,代码节选仍可在同一 XHTML 定位。