PHP OOP:业务逻辑层-DB层
使用 OOP 在业务逻辑对象和数据库之间进行分层的良好设计是什么?
what could be a good design for layering between the business logic objects and the Database using OOP?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
其中任何一个都可以(来自 Fowler 的 POEAA):
数据源架构模式:
选择哪一个取决于您选择了以下哪一个(同一来源):
域逻辑模式:
一般来说,您的业务对象与数据库模式越相似并且以 CRUD 操作为中心,您的数据源就越简单架构和领域逻辑模式可以是(但不一定是)。如果您发现自己有很多阻抗不匹配或有很多与数据库数据不直接相关的业务逻辑,那么您可能会选择域模型/数据映射器(并且可能还包括 ORM)。
Any of these would work (from Fowler's POEAA):
Data Source Architectural Patterns:
Which to choose depends on which of these you picked (same source):
Domain Logic Patterns:
In general, the more closely your business objects resemble the DB schema and is centric around CRUD operations, the simpler your Data Source Architectural and Doman Logic pattern can be (it doesnt have to though). If you find yourself with a lot of Impedance Mismatch or with lots of Business Logic not directly related to the DB data, then you might opt for Domain Model / Data Mapper (and might also include an ORM).
您可以采用多种方法来实现此目的,但我想推荐的一种方法是将 DataMapper 模式与域模型相结合。请参阅此页面了解更多信息。
通过这种方式,您可以以一种良好且简单的方式将数据访问与域模型(业务逻辑)分开。
如果您对 OOP 有点熟悉,上面链接的页面中的 UML 模型应该阐明方法的方式,以及它如何将数据库逻辑与业务逻辑分开。
There are several approaches you can take with this, but one i'd like to recommend is the DataMapper pattern combined with domain models. See this page for more information.
This way you seperate your data access from your domain models (business logic) in a good and easy way.
If you're a little bit familiar with OOP, the UML model in the page linked above should clarify the way of approach, and how it seperates database logic from business logic.