表数据网关和模型 [英] Table Data Gateway and Model

查看:115
本文介绍了表数据网关和模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我听说过这个短语胖模型,瘦身,相信我明白了这一点。在通过 Zend Quickstart Guide 工作时遇到过表数据网关模式。

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.

在我看来,这种设计模式正在提倡MVC堆栈的第四个组件。它正在从胖模型移动到瘦模型,瘦控制器和胖的TableDataGateway。从我对这种设计模式的理解,该模型不仅仅是TableDataGateway中存储的数据的存储机制。

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.

我了解了Table的优点数据网关的设计模式,抽象出数据源,我的问题不在于设计模式,而是如何适应MVC堆栈。

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.

PS我很难把我的问题变成好话。如果有人想编辑它,使其更清晰或者提出建议,我开放!

推荐答案

MVC模式可以更新如下:

The MVC schema could be updated as follow :

+------------+
| Controller |
+------------+
    ^   ^
    |   |          +------------+      +-------------+
    |   |------->  | Model      | <--> | Data access |
    |   |          +------------+      +-------------+
    |   |
    v   v
+------------+
| View       |
+------------+

数据访问部分只是另一个抽象级别(基于Data Gateway设计模式或任何其他模式/技术),这是与持久级别(文本文件,数据库或任何其他)通信的特定部分,可以轻松替换您需要更改应用程序中的持久级别(即:从MySQL到Oracle)。

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.

这篇关于表数据网关和模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆