OO question

fejkadress at hushmail.com fejkadress at hushmail.com
Mon Jan 1 20:09:19 EST 2007


First I want to say thanks everyone for helping me!

John Machin wrote:

> fejkadress at hushmail.com wrote:
> > I want to make an addressbook and I'm new to OO programming, so I
> > wonder if this sounds reasonable.
> >
> > I think of making a class Address which contains all data about one
> > person, that class can have UserDict as baseclass so I can access data
> > like object['name'], etc..
>
> Stop right there. Class Address contains all data about one *person*?
> Please consider renaming that class Person, and having a separate class
> Address.
>
> Interruption for a reality check:  A person may be related to zero, one
> or many addresses. An address may be related to zero, one or many
> persons. The relationship may take many forms e.g. "lives at", "once
> lived at", "has been noticed loitering outside", ...

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?




More information about the Python-list mailing list