2011-05-29 63 views
1

我在设计地址和客户类(模型)时遇到了问题。设计地址和客户模型

class Customer 
    (String) first_name 
    (String) last_name 
    (String) document_id 
    (String) phone 
    (String) email 
    (Address) contact_address 
    (Address) billing_address 

class Address 
    (String) street 
    (String) block 
    (String) apt 
    (Location) location 

class Location 
    (String) zip_code 
    (String) city_name 
    (State) state 
    (Country) country 

class State 
    (String) name 
    (Country) country 

class Country 
    (char[2]) tld 
    (String) name 

但State.country信息与Location.country一倍。 但是我无法想象一个情况,不是指定一个国家来说明。 否则,如果我从位置类中删除国家/地区字段,从一个国家/地区获取所有位置对象将会很奇怪。

我错过了什么吗?

如何:

class Address2 
    (String) street 
    (String) block 
    (String) apt 
    (String) zip_code 
    (String) city_name 
    (String) state 
    (String) country 

不过我会失去约顶级域名的其他信息,我会在Location.state存储重复(未优化)数据和Location.country

+0

为了便于阅读,我省略了上面所有类中的“(Integer)id”字段。 – 2011-05-29 17:25:08

+0

美国的邮政编码和缩写不是州的地方。例子包括哥伦比亚特区,美属萨摩亚,密克罗尼西亚联邦和欧洲武装部队。 USPS分配了65个双字母缩写; 15个“额外”中的大多数实际上是国家。 – 2011-05-29 18:20:54

回答

0

为什么你需要一个Location类中的国家?

就像你可以从state.countryId检索tld一样,你可以从location.stateId检索国家。

+0

你建议放弃'Location.country'并在我的搜索查询中使用'Location.state.country'而不是? – 2011-05-29 17:34:39

+0

是的,确实如此。您还必须查询“Customer.contact_address.location.state”,以便更进一步? ;)_这只是为了存储。如果表现或复杂性成为问题,您应该放弃一个或多个班级._ – NGLN 2011-05-29 17:47:00

+0

也就是说,您的国家的管理员班级可以(并且应该)拥有国家成员。 – NGLN 2011-05-29 17:54:16