Best way to model Customer <--> Address

后端 未结 12 1641
被撕碎了的回忆
被撕碎了的回忆 2020-11-30 02:22

Every Customer has a physical address and an optional mailing address. What is your preferred way to model this?

Option 1. Customer has fo

12条回答
  •  一生所求
    2020-11-30 02:48

    In most code I write nowadays every customer has one and only one physical location. This is the legal entity beeing our business partner. Therefore I put street, city etc in the customer object/table. Often this is the possible simplest thing that works and it works.

    When an additional mailing address is needed, I put it in a separate object/table to not clutter the customer object to much.

    Earlier in my career I normalized like mad having an order referencing a customer which references a shipping address. This made things "clean" but slow and inelegant to use. Nowadays I use an order object which just contains all the address information. I actually consider this more natural since a customer might change his (default?) address, but the address of a shipment send in 2007 should always stay the same - even if the customer moves in 2008.

    We currently implement the VerySimpleAddressProtocol in out project to standardize the fields used.

提交回复
热议问题