开发者

implementing many to one relationships in object model

Suppose a Person object may have many Addresses but must have one

Do you favor making the one required Address explicit in the object model? If so, any implementation tips?

Cheers,

Berryl

Person{
    Address TheRequiredAddress {get;}    

    IList<Address> OtherA开发者_开发问答ddresses {....}
}


I like this question. As with most design decisions, this is contextual. How will this be used.

Assume I have a primary address in Seattle and a summer house in Phoenix, and a PO box for business purposes. Will my primary address have special priority over my other addresses, or is the choice of address arbitrary? Will you try to locate me in Seattle before you try my summer house or my PO box?

In the case where the primary address is treated differently, I would store it in an explicitly separate location. Otherwise, store them in an arbitrarily ordered collection and enforce the requirement for at least one within the class implementation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜