1

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

Matt
  • 22,721
  • 17
  • 71
  • 112
Matt Harasymczuk
  • 1,728
  • 2
  • 21
  • 29
  • For easy of read, I have omitted an `(Integer) id` field in all above classes. – Matt Harasymczuk May 29 '11 at 17:25
  • The USA has ZIP codes and abbreviations for places that aren't states. Examples include the District of Columbia, American Samoa, Federated States of Micronesia, and Armed Forces Europe. The USPS has assigned 65 two-letter abbreviations; most of the 15 "extras" are actually countries. – Mike Sherrill 'Cat Recall' May 29 '11 at 18:20

1 Answers1

0

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.

NGLN
  • 43,011
  • 8
  • 105
  • 200
  • You are suggesting to drop `Location.country` and use `Location.state.country` in my search queries instead? – Matt Harasymczuk May 29 '11 at 17:34
  • Yes, indeed. You will also have to query for `Customer.contact_address.location.state` so why not one step further? ;) _This is just for storage. If performance or complexity becomes an issue, you should drop one or more classes instead._ – NGLN May 29 '11 at 17:47
  • That said, your controller class for State can (and should?) have a country member though. – NGLN May 29 '11 at 17:54
  • Then I should split apart Location.zip_code and Location.city_name as one zip_code can be assigned to more than one city, and one city is able to have more than one zip_code – Matt Harasymczuk May 29 '11 at 17:58
  • That depends on how far you want or need to normalize. e.g. A phone number is splittable also. – NGLN May 29 '11 at 18:03
  • Hmm, I hear you now. If one cannot be resolved without the other, than splitting is useless. But you cóuld add a seprarate table with every valid combination for checking the match of both. – NGLN May 29 '11 at 18:25