知识卡片
绕过服务层破坏职责边界
服务层承载业务规则,数据访问对象负责持久化;若调用方为图方便直接调用 DAO,业务规则可能被绕过,调用方还会依赖存储细节。这是一种职责边界被穿透的错误抽象。判断复用是否安全,应看调用是否保留业务约束,而不能只看方法是否可访问。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
原书出处
参考来源
- 位置:《Principles of Software Architecture Modernization》第1章《What’s Wrong with Monoliths?》(源文件:`_epub-src/OPS/ch01.xhtml`,归一化正文 [24977:29196))
- 结论依据:原文分别给服务类和 DAO 指定业务规则与数据访问职责,并明确指出直接调用 DAO 会跳过业务规则、增加耦合。
- 原始内容:Service classes are responsible for holding business rules. Data Access Objects (DAO) should handle persistence and data access. No rules are being enforced here, which is bad, and boundaries are not being respected. Calling the DAO directly is the wrong abstraction because it skips the business rules and introduces high coupling.