知识卡片

普通读书笔记卡 · 3497.b

仓储返回领域对象

理解等级:高级

仓储向业务层返回领域对象时,业务规则可使用订单的业务语义,而不必依赖 ORM 类或数据库会话。转换逻辑属于数据适配器;若领域对象仍持有 ORM 模型指针,隔离就不完整,应把此例外列为设计债务,而非声称存储技术已完全可替换。参见 [[仓储接口隔离存储细节]]。

这张卡片看不懂?

已有反馈 · 0 / 10 条

    还没有人提交反馈。

    原书出处

    参考来源

    - 位置:《Microservice APIs》第 7 章《Service implementation patterns for microservices》(源文件:_epub-src/OEBPS/Text/07.htm) - 结论依据:原文明确拒绝让仓储返回数据库模型,改为返回业务层 Order 对象;同时示例又把 ORM 模型指针传给 Order,表明隔离在本书实现中并不彻底。 - 原始内容:Why is it a bad idea to return instances of the database models through the repository? Because it defeats the purpose of the repository, which is to decouple the business layer from the data layer. ... Instead, we’ll return objects that represent orders from the business layer domain.