Zend的模型架构 [英] zend models architecture

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

问题描述

让我们说我有一个数据库的两个表:项目和用户。我创建了两个型号,扩展Zend_Db_Table_Abstract: Model_DbTable_Users Model_DbTable_Projects

Let's say I have two tables in a database: projects and users. I create two models, that extend Zend_Db_Table_Abstract: Model_DbTable_Users and Model_DbTable_Projects.

现在,这是一个好的模式来创建 Model_DbTable_Users 类中 Model_DbTable_Projects 的一个实例?换句话说:这是确定把任何逻辑在这个模型中,或者我应该创建另一个类,使用 Model_DbTable_Users Model_DbTable_Projects

Now, is it a good pattern to create an instance of Model_DbTable_Projects inside the Model_DbTable_Users class ? In other words: is it OK to put any logic in this model, or should I create another class, that uses Model_DbTable_Users and Model_DbTable_Projects?

我用把所有的逻辑模型,扩展Zend_Db_Table_Abstract,但在大的项目它可以​​使code非常洁净。所以,你可以给我的模型架构的任何意见(在文章的链接将是巨大的!)。

I use to put all the logic in models, that extend Zend_Db_Table_Abstract, but in large projects it can make code very unclean. So, can you give me any advice on models architecture(links on articles would be great!).

推荐答案

我是项目负责人,通过1.0版本的Zend框架项目。我的贡献主要是在Zend_Db的组成部分。

I was the project lead for the Zend Framework project through version 1.0. My contributions were mainly in the Zend_Db component.

我经常建议,人们应该使用的Domain模型的图案,并避免在贫血域模型反模式。请记住,表不是一个模型。

I frequently advise that people should use the Domain Model pattern and avoid the Anemic Domain Model antipattern. Remember that a Table is not a Model.

你的模型是一个类(延伸出的基类)为code,封装业务逻辑。一个模型和一个表之间的关系是不是IS-A,它的HAS-A(或已经多)。该模型将数据库持久作为实现细节。模型的消费者不应该有你的数据库结构线索(这允许您更改数据库结构不改变型号的接口)。

Your Model is a class (extending no base class) for code that encapsulates your business logic. The relationship between a Model and a Table isn't IS-A, it's HAS-A (or HAS-MANY). The Model treats database persistence as an implementation detail. The consumer of a Model should have no clue about your database structure (this allows you to change database structure without changing the Model's interface).

我基本上重复答案我给在Zend框架模型

I'm basically repeating the answer I gave to Models in the Zend Framework.

下面是一些更多阅读:

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

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