知识卡片
活动记录耦合业务与存储
活动记录把数据字段和领域操作放在同一对象中,简单的数据库操作可直接承载业务能力;当业务协作跨多个对象或需替换 ORM、存储技术时,业务逻辑就容易受数据模型牵动。它适合操作与记录高度对应的场景,复杂协作应先评估这种耦合。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
原书出处
参考来源
- 位置:《Microservice APIs》第 7 章《Service implementation patterns for microservices》(源文件:_epub-src/OEBPS/Text/07.htm)
- 结论依据:原文定义活动记录同时携带数据和领域逻辑,说明其简单场景收益,并指出直接在业务层使用数据库模型会使业务依赖 ORM 和存储技术。
- 原始内容:This is called the active record pattern , which represents objects that carry both data and domain logic. ... This approach works for simple cases; however, it couples the implementation of the business layer to the database and to the ORM framework of choice.