OO question

Tim Henderson tim.tadh at gmail.com
Mon Jan 1 21:36:10 EST 2007


On Jan 1, 8:09 pm, fejkadr... at hushmail.com wrote:
> Lets say I have those two classes, Person and Address. How would one
> implement the relationship between them? First, a Person can have one
> or more addresses (or none), that could be represented as a list of
> Addresses, right? But then, if I have an Address I want to see which
> persons who live there, then I would have a list of Persons in each
> Address.
>
> Is this doubly-linked way of doing it a good way of doing it, or is
> there
> a better "OO way" I haven't learned yet?

Since you are making an address book and not a person book I would
start out by making a simple list of addresses. Each address could have
a "person" or a "name" field. You could then sort your list by the name
of each person associated with each address. If an address has no
person associated with it then you put it at the beginning (or end if
you want) of the list. I think this would most closely mimic how a
rolodex works. It doesn't really matter if you implement it as a list
of dictionaries or a list classes I believe they would be equivalent in
this case.

tim




More information about the Python-list mailing list