知识卡片
值对象消除隐含约定
把邮箱、电话、身高都表示为字符串或整数,会让合法格式、单位、转换规则散落各处。值对象把验证和操纵该值的业务逻辑集中起来:合法电话才能构造,身高能够按统一语义换算单位,调用者不必记住隐含约定。它的价值不止封装校验,更在让类型直接表达业务含义。
相关:[[值对象以值相等]]。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 应对复杂业务逻辑 · 查看原书依据
First, notice the increased clarity. Take, for example, the country variable. There is no need to elaborately call it “countryCode” to communicate the intent of it holding a country code and not, for example, a full country name. The value object makes the intent clear, even with shorter variable names. Second, there is no need
参考来源
- 位置:《Learning Domain-Driven Design》第6章《应对复杂业务逻辑》(来源项目:book-sources;源文件:extracted/Learning Domain-Driven Design/_epub-src/OEBPS/ch06.html)
- 结论依据:原文围绕本卡所述机制给出定义、适用条件及相关取舍,以下摘录为直接依据。
- 原始内容:First, notice the increased clarity. Take, for example, the country variable. There is no need to elaborately call it “countryCode” to communicate the intent of it holding a country code and not, for example, a full country name. The value object makes the intent clear, even with shorter variable names. Second, there is no need