← 返回刚才阅读的位置

知识卡片

普通读书笔记卡 · 1971.o.1.c.1.a.1.c.1.a

分开付款计算与贷款变更

理解等级:中级

原书的联贷本金付款教学案例中,初版 Loan.distributePrincipalPayment(amount) 一边按各出借人份额计算付款分配,一边减少贷款中的份额。名称不足以暴露两个后果,也让试算无法安全重用。

图10.17把它拆为 calculatePrincipalPaymentShares(amount)(只计算分配)与 applyPrincipalPaymentShares(distribution)(实际改状态)。客户先得到分配,再明确执行变更;这一步改善副作用可见性,但仍未解决计算逻辑都堆在 Loan 中的问题。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • 原书第10章|Angles of Attack · 查看原书依据

      This design already has INTENTION-REVEALING INTERFACES. But the distributePaymentPrincipal() method does a dangerous thing: It calculates the shares for distribution and also modifies the Loan. Let's refactor to separate the query from the modifier.

    参考来源

    - 位置:《Domain-Driven Design: Tackling Complexity in the Heart of Software》第82章《Angles of Attack》(源文件:_epub-src/0321125215_ch10lev1sec9.html;单元02) - 结论依据:原文和图10.16–10.17对比单一方法同时计算/修改与拆出的计算函数、状态命令,并说明扩展更多交易类型时 Loan 仍会膨胀。 - 原始内容:This design already has INTENTION-REVEALING INTERFACES . But the distributePaymentPrincipal() method does a dangerous thing: It calculates the shares for distribution and also modifies the Loan . Let's refactor to separate the query from the modifier.