知识卡片
账户条目保留余额变动历史
只保存账户余额会丢失每次变化的由来。Account 可持有多条 Entry:增加价值记正条目,减少价值记负条目;条目保留后,余额是条目金额合计的结果。余额可按需计算,也可缓存,但这属于 Account 接口之下的实现选择。
这是原书转述 Fowler 的基础会计分析模型,用于启发后续贷款计提案例;并不意味着所有应用都需要完整账务严谨度。
结构图:
classDiagram
class Account {
+balance : Quantity
}
class Entry {
+amount : Quantity
+whenCharged : Timepoint
+whenBooked : Timepoint
}
Account o-- "*" Entry : 保留变动
note for Account "balance = sum(entries.amount)"
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 原书第11章|Example Earning Interest with Accounts · 查看原书依据
Value can be added by inserting an Entry. Value can be removed by inserting a negative Entry. Entries are never removed, so the whole history is retained. The balance is the combined effect of all Entries. This balance could be computed on demand or cached, an implementation decision that is encapsulated by the Account interface.
参考来源
- 位置:《Domain-Driven Design: Tackling Complexity in the Heart of Software》第84章《Example Earning Interest with Accounts》(源文件:_epub-src/0321125215_ch11lev2sec1.html;单元01)
- 结论依据:原文和图11.2说明条目不删除以保留历史,余额为全部条目的合计;现算或缓存由账户接口封装。
- 原始内容:Value can be added by inserting an Entry . Value can be removed by inserting a negative Entry. Entries are never removed, so the whole history is retained. The balance is the combined effect of all Entries . This balance could be computed on demand or cached, an implementation decision that is encapsulated by the Account interface.