← 返回刚才阅读的位置

知识卡片

普通读书笔记卡 · 1971.o.1.b.4.d.1.c.4.b.6

处理事件工厂方法隐藏种类差异

理解等级:中级

Handling Event 的不同种类可能需要不同属性:装载事件关联 Carrier Movement,其他事件未必需要。原书给出 newLoading(Cargo, CarrierMovement, Date) 工厂方法,填入货物、类型、时间和承运段;将来事件种类可用子类或不同初始化方式,调用方仍按业务动作创建,不需了解具体实现。此为原书 Java 教学代码,是否采用静态方法取决于实际设计。参见[[工厂隔离复杂创建职责]]。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • 原书第07章|Object Creation · 查看原书依据

      The Handling Event in the model is an abstraction that might encapsulate a variety of specialized Handling Event classes, ranging from loading and unloading to sealing, storing, and other activities not related to Carriers.

    参考来源

    - 位置:《Domain-Driven Design: Tackling Complexity in the Heart of Software》第56章《原书第07章|Object Creation》(源文件:_epub-src/0321125215_ch07lev1sec8.html;`newLoading` 代码示例) - 结论依据:原文指出事件类型有不同属性和潜在子类,工厂方法封装具体类型选择及初始化,举装载事件为例。 - 原始内容:The Handling Event in the model is an abstraction that might encapsulate a variety of specialized Handling Event classes, ranging from loading and unloading to sealing, storing, and other activities not related to Carriers . ... The FACTORY is responsible for knowing what class was to be instantiated and how it should be initialized.