OO question

John Machin sjmachin at lexicon.net
Mon Jan 1 03:14:40 EST 2007


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", ...

OK, now you can resume your normal programming ;-)

BTW, why object['name'] and not object.name?

Cheers,
John




More information about the Python-list mailing list