表数据网关和模型
我听说过“胖模型,瘦控制器”这句话,并且相信我理解它的含义。在学习 Zend 快速入门指南时,我遇到了表数据网关模式。
在我看来,这种设计模式正在倡导 MVC 堆栈的第四个组件。它正在从“胖模型”转向“瘦模型、瘦控制器和胖 TableDataGateway”。根据我对这种设计模式的理解,模型只不过是 TableDataGateway 填充到其中的数据的存储机制。
我了解表数据网关设计模式通过抽象数据源的优势,我的问题不是设计模式,而是它如何融入 MVC 堆栈。
PS 我很难用恰当的语言表达我的问题。如果有人想编辑此内容以使其更清晰或提出建议,我愿意!
I've heard the phrase "fat model, thin controller" and believe I understand it's implications. While working through the Zend Quickstart Guide I have come across the Table Data Gateway pattern.
It seems to me that this design pattern is advocating a fourth component to the MVC stack. It is moving away from a "Fat Model" to "thin model, thin controller and fat TableDataGateway". From my understanding of this design pattern, the Model becomes very little more than a storage mechanism for the data that the TableDataGateway stuffs into it.
I understand the advantages of the Table Data Gateway design pattern with abstracting our data source, my question isn't about the design pattern, but rather how it fits into the MVC stack.
P.S. I'm having a bit of a hard time getting my question into good words. If someone wants to edit this to make it clearer or make a suggestion I'm open!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
MVC 架构可以按如下方式更新:
数据访问部分只是另一个抽象级别(基于数据网关设计模式或任何其他模式/技术),它是与持久级别(文本文件)对话的特定部分、数据库或任何其他),如果您需要更改应用程序中的持久级别(即:从 MySQL 到 Oracle),可以轻松替换它们。
这样,您唯一需要重写的部分是数据访问级别,并且应用程序的其余部分仍然可以工作。模型的任务现在是以控制器或视图可以使用的方式格式化数据。
这可能不是最好或最完整的答案,但至少是一个开始。
The MVC schema could be updated as follow :
The data access part is just an other level of abstraction (based on the Data Gateway design pattern, or any other pattern/technique) which is the specific part that talk to your persistent level (text files, database or any other) which can be easily replaced if you ever need to change your persistent level in your application (ie: going from MySQL to Oracle).
This way, the only part you have to rewrite is the data access level and the rest of the application is still working. The task of the model is now to format data in a way that can be used either by the controller or by the view.
This might not be the best or the most complete answer, but its at least a beginning.