[Tutor] Creating subclasses (newbie)

Alan Gauld alan.gauld at blueyonder.co.uk
Thu Jun 24 07:45:15 EDT 2004


> On to my next related question. Is the best way to build up
> a relation of objects through the use of lists (or
> dictionaries or tuples). 

Yes, usually dictionaries for the sort of thing you describe...

> I'm writing an application to manage a catalogue of magazines 

> objects Title, Issues, Articles - there will be many titles,
> which in turn will hold many issues - so is the best way of
>  managing this giving each Title a list, which holds each
> Issue object instance? In turn, each Issue will hold a list
> (mutable) which can then hold the article instances. How
> does that sound as a design?

I'd go with dictionaries, and why would the list of articles 
be mutable? Surely the articles in an Issue is fixed?
 
But I'd be careful of creating too many classes. Think about 
each classes responsibilities and behaviours. In this case 
it may be that you only need data for some of the items.

Also consider data volumes, it may be that you have enough 
magazines to warrant a database solution. At least think 
about how you will store the data to/from files. Using 
dictionaries leads nicely to the shelve module (Which 
creates a file that acts a lot like a dictionary).

Just some thoughts.

> ps. forgive me for posting directly to you, but the list
> seems to be undergoing some problems at the moment. 

No probs I've CCd the reply anyway.

Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld



More information about the Tutor mailing list