我正在开发基于Zend Framework组件的CMS。有些该CMS数据库表的是如下:模型粒化?
site
| id | name |
-------------
locale
| languageCode | regionCode |
-----------------------------
site_locale // link sites with locales
| siteId | languageCode | regionCode | isActive | isDefault |
-------------------------------------------------------------
我有一个名为Site
模型,该模型包括,除其他外,下面的方法:我的是那种
getId()
getName()
listLocales() // list all locales for this site
我应该怎么颗粒化定义模型栅栏:
一个选项将返回SiteLocale
对象/模型(即一个数据库表表示)从listLocales()
方法,而这些SiteLocale
合作对象ntain以下方法:
getSite() // returns the Site model
getLocale() // returns a Zend_Locale
isActive() // is this locale active for the site this model represents?
isDefault() // is this the default locale for the site this model represents()
另一种选择是简单地建立在Site
模型下面的方法,并用它做:
getDefaultLocale() // simply return the default site locale as Zend_Locale
listActiveLocales() // simply return all active site locales as Zend_Locales
listAllLocales() // simply return all site locales as Zend_Locales
你觉得什么是正确的方式来走?为什么?
此外,第一个选项(或者甚至两个选项)是否会违反Law of Demeter?
编辑(1月22日)
虽然我喜欢Jeff's答案,我还在开新/其他观点。
嗨,杰夫,谢谢你的回应。关于重复,我使用了引用完整性约束(InnoDB),因此languageCode和regionCode是带有约束的外键。我喜欢这种风格,因为它可以轻松获取多对多行集而无需加入语言环境表。但我确实希望能够添加与网站分离的语言环境。希望这是有道理的。无论如何,我明白你在说什么。我想你说服我使用这两个选项,因为我将利用你提到的场景(前端第一,后端管理员第二)。感谢您的输入。 – 2010-01-22 01:26:02
再次感谢杰夫。我要吃我的蛋糕,也要吃。 :) – 2010-01-28 15:38:26