知识卡片

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

接口名称表达领域意图

理解等级:中级

意图揭示接口用类型、方法和参数名说明领域动作的目的与效果,而不要求调用者先读内部实现。名称应采用团队的统一语言:例如 mixIn(Paint) 表示把一种颜料混入另一种,比 paint(Paint) 更能让调用代码表达业务意图。若只能从实现猜用途,调用者可能把偶然成立的行为当作契约。名称仍不能说明全部副作用和约束,还需后续的断言等手段补足。参见[[代码行为与名称须对齐]]。

这张卡片看不懂?

已有反馈 · 0 / 10 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • 原书第10章|Intention-Revealing Interfaces · 查看原书依据

      Name classes and operations to describe their effect and purpose, without reference to the means by which they do what they promise. This relieves the client developer of the need to understand the internals. These names should conform to the UBIQUITOUS LANGUAGE so that team members can quickly infer their meaning. Write a test for a behavior before creating it, to force your thinking into client developer mode.

    参考来源

    - 位置:《Domain-Driven Design: Tackling Complexity in the Heart of Software》第73章《Intention-Revealing Interfaces》(源文件:_epub-src/0321125215_ch10lev1sec1.html) - 结论依据:原文把类名、方法名和参数名组成的公开接口视为传达设计意图的机会,要求名称描述效果与目的、符合统一语言;颜料重构例子示范了含糊名到领域动作名的变化,并说明命名不能独自刻画全部效果。 - 原始内容:Name classes and operations to describe their effect and purpose, without reference to the means by which they do what they promise. This relieves the client developer of the need to understand the internals. These names should conform to the UBIQUITOUS LANGUAGE so that team members can quickly infer their meaning. Write a test for a behavior before creating it, to force your thinking into client developer mode.