[Tutor] Criticism / Suggestions

Jeff Shannon jeffshannon at gmail.com
Wed Mar 2 08:44:43 CET 2005

On Wed, 02 Mar 2005 01:17:28 -0500, Bill Kranec <billk at fastmail.fm> wrote:

> [...] I wanted to be able to define
> multiple tournament objects off of the same roundlist, to avoid
> generating the list every time a new object is created.  I think what I
> really want to do is have a separate Round class, from which Tournament
> inherits the list of rounds.  I have started to implement something like
> this in my most recent version, but haven't finished it yet.  ( I need
> to understand class inheritance better. )

This sounds like a good idea, but inheritance is probably not the
right way to solve it.  Every Tournament contains a list of Rounds,
but it's probably not accurate to say that a Tournament is a type of
Round.  (Inheritance works best when it describes an "is-a"
relationship, not a "has-a" relationship.)

It's probably better to have Tournament and Round be independent
classes, but have Tournament instances hold a list of Rounds (which
may be passed in during initialization, or may be added later).  This
is called "composition", and is just as important (or perhaps more
important) of an idea as inheritance, even though inheritance gets all
the press.  ;)

Jeff Shannon

More information about the Tutor mailing list