设计地址和客户模型

发布于 2024-11-10 02:05:53 字数 958 浏览 2 评论 0原文

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

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

但是我将丢失有关 tld 的其他信息,并且我将在 Location.state 和 Location.country 中存储重复的(未优化的)数据

I have encountered a problem, when I was designing an address and a customer classes (models).

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

But information in State.country doubles with Location.country.
However I can't imagine a situation, of not assigning a country to state.
Otherwise if I drop country field from Location class, it would be odd to get all locations objects from one country.

Am I missing something?

How about:

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

However I will lose additional information about tlds, and I will store duplicated (not optimized) data in Location.state and Location.country

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

开始看清了 2024-11-17 02:05:53

为什么 Location 类别中需要一个国家/地区?

就像您可以从 state.countryId 检索 tld 一样,您可以从 location.stateId 检索国家/地区。

Why do you need a country in the Location class?

Just like you can retrieve the tld from state.countryId, you can retrieve the country from location.stateId.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文