返回主题:契约式设计

知识卡片

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

生成器接口以规格描述结果

理解等级:中级

按要求生成时,Specification 描述输出必须满足什么,生成器自己决定怎样达到。客户端因此可理解、测试接口而无需读完整算法;若同一规格也支持验证,还可检查产物。原书举战机需求及文字绕图排列作类比,不是具体实现保证。生成也可能是重新配置已有对象。参见[[规格统一验证查询与按需生成]]。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    参考来源

    - 位置:《Domain-Driven Design: Tackling Complexity in the Heart of Software》第70章《How to Model Less Obvious Kinds of Concepts》,Building to Order (Generating)(源文件:_epub-src/0321125215_ch09lev1sec2_split_000.html) - 结论依据:原文将输出条件与生成算法分离,并指出同一规格可用于验证产物。 - 原始内容:When the Pentagon wants a new fighter jet, officials write a specification. [...] Many computer programs generate things, and those things have to be specified. When you place a picture into a word-processing document, the text flows around it. [...] The SPECIFICATION declares the requirements for the output but does not define how that result is reached. The interface communicates its rules explicitly, so developers can know what to expect from the generator without understanding all details of its operation. [...] Last, but not least, this kind of interface is easier to test, because the model contains an explicit way to define input into the generator that is also a validation of the output . That is, the same SPECIFICATION that is passed into the generator's interface to constrain the creation process can also be used, in its validation role (if the implementation supports it) to confirm that the created object is correct. [...] Building to order can mean creation of an object from scratch, but it can also be a configuration of preexisting objects to satisfy the SPEC .