Granulation models?

I develop CMS mainly based on the components of the Zend Framework. Below are some database tables for this CMS:

site
| id | name |
-------------

locale
| languageCode | regionCode |
-----------------------------

site_locale // link sites with locales
| siteId | languageCode | regionCode | isActive | isDefault |
-------------------------------------------------------------

I have a model with a name Sitethat consists, among other things, of the following methods:

getId()
getName()
listLocales() // list all locales for this site

I’m kind of on a fence about how granular I have to define models:

One option is to return SiteLocaleobjects / models (in other words, a database table view) from a method listLocales()where these objects SiteLocalecontain the following methods:

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()

Another option is to simply create the following methods in the model Siteand do with it:

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

What do you think is the right way? And why?

In addition, will the first option (or perhaps even both) violate the Law of Demeter ?

(22 jan)
, / .

+5
1

-, : , , , . locale site_locale. , , - , .

, . , . , , , ?

site_locales = site.listLocales()
foreach (site_locale in site_locales) {
    if site_locale.isDefault() {
        do_something(site_locale.getLocale())
    }
}

, :

do_something(site.getDefaultLocale())

. , .

, , , SiteLocales , , getDefaultLocale(), listActiveLocales(), listAllLocales(), , , . .

, . , , , , , , . , , - , , . , - .

+3

All Articles